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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Random Generator Function

Status
Not open for further replies.

nancier

MIS
Dec 27, 2004
50
US
Would anyone know of a Random Generator Function or how to create one where the user would supply the seed number instead of using the system clock to choose the seed. I need to be able to enter the seed myself so someone else could reproduce the results by using the same seed.

Thanks

 
See the ubiquitous {F1}[/color (aka HELP). It should provide an adequate -discription of the use or the parameter.





MichaelRed


 
Yes, I've seen that many times before but either I don't understand it or it doesn't work. I'm using this function in a module:

Option Compare Database
Function GetRan(field As String)
Randomize
GetRan = Rnd(1)
End Function

and then I'm using this expression in the query
RanSort: GetRan([ID])

I'm not understanding how I can modify the function to able to add my own seed value where results could be reproduced on another computer using the same database.
Thanks


 
A few quick observations.

"Randomize" is used to initalize "Rnd", so the intrinsic function (RND) is initalized to a random starting point every time it is called. Since it is initalized with a random value the sequence will also be random. Per Mr. Ubiquitous (see earlier post):

Mr. Ubiquitous said:
Note To repeat sequences of random numbers, call Rnd with a negative argument immediately before using Randomize with a numeric argument. Using Randomize with the same value for number does not repeat the previous sequence

You provide an input argument "field as string" to your function - but do not use it. At best, this is useless.

Providing the Seed (to the intrinsic function) as a positive value simply tells the intrinsic function to the next value in th e sequence. Since the sequence is re-initalized on each call, there is no value to this, as it is EXACTLY the same as supplying NO argument.







MichaelRed


 
Hi, thanks alot for the help!!! I put this as the Function.

Function GetRan(field As String)
Randomize -1
Randomize CLng(777)
GetRan = Rnd(1)
End Function

and this in a column field in the query
RanSort: GetRan([ID])

My goal was to query for 5 items from the Access 2000 table which worked ok. Then if I re-run the query I get 5 different numbers even though I'm still using the same seed of 777. Do you know why I don't get the same 5 numbers I originally got? Then I shut down and restart access and get the original 5 numbers again.

I then copied the database to two other computers, one running Access 97 and the other Access 2000. I get the identical 5 results on the Access 2000 computer and different results on the Access 97 computer. Any idea why the results on the Access 97 machine are different and the two Access 2000 machines give the same results?

Thanks a Million!!!
 
Sorry. Haven't used ver '97 is a while, don't even have it installed anywhere anymore. While I do not RECALL and changes in RND or Randomize, it would be worth the effort to check the docs (Mr. Ubiquitous, AGAIN!) on the 'older' systems to be sure they read the same. I'm currently running ver '03 (aka XP) but I'm SURE that these haven't changed from 2K.





MichaelRed


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top