Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Random Number Generator in Excel

Status
Not open for further replies.

Jamie2002

Technical User
Sep 17, 2001
62
GB
I have the following piece of code for generating 6 random numbers between 1-49. How do I need to adapt this in order to have the number of random no.s, and the range ie 1-1000 to pick from as variables.....?



Sub Resample()
Dim i As Long
Dim hold(49) As Single, Hold2(49) As Single
Randomize

For i = 1 To 49
Hold2(i) = i
Next i
For jj = 1 To iteration
For i = 1 To 49
hold(i) = Rnd
Next i
Call DoubleSort(49, hold, Hold2)
For i = 1 To 6
Cells(jj + 3, i) = Hold2(i)
Next i
Next jj

End Sub


Thanks.
 
This is also part of the code

Sub DoubleSort(n As Long, x() As Single, y() As Single)
Dim xTemp As Double
Dim yTemp As Double
Dim i As Long
Dim j As Long

For j = 2 To n
xTemp = x(j)
yTemp = y(j)
For i = j - 1 To 1 Step -1
If (x(i) <= xTemp) Then GoTo 10
x(i + 1) = x(i)
y(i + 1) = y(i)
Next i
i = 0
10 x(i + 1) = xTemp
y(i + 1) = yTemp
Next j

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top