Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How can I select random whole nos from 1-16 without repeating?

How can I select random whole nos from 1-16 without repeating?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default How can I select random whole nos from 1-16 without repeating?

http://www.mcgimpsey.com/excel/udfs/randint.html

also see Laurent Longre's MRAND function in his MoreFunc.xll at
http://xcell05.free.fr/english/index.html

Jerry

"ilena" wrote:

How can I select random whole nos from 1-16 without repeating?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 139
Default How can I select random whole nos from 1-16 without repeating?

ilena:

try,

Dim n2&, i&, rr&, rd(), rg As Range
n2 = 16
Set rg = Range("b1")
ReDim rd(1 To n2, 1 To 1)
Randomize
For i = 1 To n2
Do
rr = Int((n2) * Rnd + 1)
Loop While Not IsError(Application.Match(rr, rd, 0))
rd(i, 1) = rr
Next i
With rg.Resize(n2)
.Value = rd
End With

--
天行健,君*以自強不息
地勢坤,君*以厚德載物

http://www.vba.com.tw/plog/


"ilena" wrote:

How can I select random whole nos from 1-16 without repeating?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default How can I select random whole nos from 1-16 without repeating?

for smallish lists use the worksheet. let column A hold the list of numbers
in sequence then in B put =RAND() . Now sort the table by column B and save
the list in A into memory. create an index that walks the array. here's some
simple code...just copy into a module. run 'Initialise' first, the the sheet
type into a cell
=GetNumber()

as I set the function to volatile, each time you hit F9, the value changes
Option Explicit
Public myrand() As Double
Private myrand_index As Long
Sub Inititalise()
generate 1, 16
End Sub
Public Function GetNumber()
Application.Volatile
If myrand_index = 0 Then Exit Function

GetNumber = myrand(myrand_index)
myrand_index = myrand_index + 1

If myrand_index UBound(myrand, 1) Then
myrand_index = 1
End If

End Function
Private Sub generate(minimim As Integer, maximum As Integer)
Dim index As Long
Dim ws As Worksheet
Dim status As Boolean
status = Application.ScreenUpdating
Application.ScreenUpdating = False
Set ws = Worksheets.Add
With ws
For index = 1 To maximum - minimim + 1
.Cells(index, 1) = index + minimim - 1
.Cells(index, 2).Formula = "=rand()"
Next

.Range(.Range("a1"), .Cells(index - 1, 2)).Sort .Range("B1")

ReDim myrand(1 To index - 1)

For index = 1 To index - 1
myrand(index) = .Cells(index, 1)
Next
myrand_index = 1
End With
Application.DisplayAlerts = False
ws.Delete
Application.DisplayAlerts = True
Application.ScreenUpdating = status
End Sub



"ilena" wrote:

How can I select random whole nos from 1-16 without repeating?

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Non repeating random numbers Rowland Excel Worksheet Functions 3 January 29th 07 11:31 PM
random numbers repeating Harlan Grove Excel Discussion (Misc queries) 2 January 23rd 07 11:30 PM
random numbers repeating Ashkan Excel Discussion (Misc queries) 0 January 23rd 07 05:42 AM
random number without repeating? nonoi via OfficeKB.com Excel Worksheet Functions 2 July 11th 05 05:59 AM
random non-repeating names rivet Excel Programming 2 February 17th 05 03:51 AM


All times are GMT +1. The time now is 02:13 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright 2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"