Random Number Generator

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I am trying to create a set of random numbers to populate a 1 column table. My goal is to create a table of say 50 values with each "random" value between say 1 and 500. I need to ensure that the same value isn't selected twice. I hope this makes sense

Thanks in advance for any help or advice..
 
Hi,


Append 500 records to a table with an incremental autonumber. Select the
top N records order by the random value.

===========================
Public Sub Whatever()

Dim i As Long
Dim myRst As DAO.Recordset
Dim bd As Recordset: Set db = CurrentDb
db.Execute "CREATE TABLE testing ( f1 AUTOINCREMENT, f2 double) "


For i = 1 To 500
db.Execute "INSERT INTO testing(f2) VALUES( Rnd()) "
Next i


Set myRst = db.OpenRecordset("SELECT TOP 50 f1 FROM testing ORDER BY f2
")

'db.Execute "DROP TABLE testing"
End Sub
===========================


Hoping it may help,
Vanderghast, Access MVP



Gregory said:
Hi!

I am trying to create a set of random numbers to populate a 1 column
table. My goal is to create a table of say 50 values with each "random"
value between say 1 and 500. I need to ensure that the same value isn't
selected twice. I hope this makes sense.
 
Back
Top