View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rich_z[_26_] Rich_z[_26_] is offline
external usenet poster
 
Posts: 1
Default Random Selection


You don't say if the accounts are consecutively numbered or not.

If they are consecutively numbered you can use:


Code:
--------------------

int(1+(150*rnd(1)))

--------------------


If they are not consecutively numbered then place the accounts into an
array numbered 1-150 and use the formula above to generate a pointer
into the array (likewise if the accounts are non-numeric)

RND is a psuedo Random number generator. This means that it's results
are reproduceable (if you restart Excel...).

To reproduce a given set of 'Random' numbers you use the 'Randomize'
statement.

To give the numbers an almost totally random nature, use the
statement:


Code:
--------------------

Randomise(Now())

--------------------



Code:
--------------------

Sub Temp1()
Dim I As Integer
'*
Randomize (Now())
For I = 1 To 14
Debug.Print Int(1 + (150 * Rnd(1)))
Next I
End Sub

--------------------


Gives the following results over 3 runs:

94
78
114
67
85
52
79
95
124
58
36
40
125
132

46
47
35
46
81
100
33
70
143
150
120
37
51
140

122
21
14
93
45
24
122
52
101
92
148
71
98
133


If you want to make sure a number is not used twice then you will have
to build an array of the numbers chosen (either in a string or using
Redim)

Regards

Rich


--
Rich_z
------------------------------------------------------------------------
Rich_z's Profile: http://www.excelforum.com/member.php...o&userid=24737
View this thread: http://www.excelforum.com/showthread...hreadid=386134