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!

Ignore previous cyork question - HELP with NEW PROBLEM

Status
Not open for further replies.

cyork

MIS
Apr 4, 2001
34
CA
I have identified my problem but have no idea why it is occuring:

- I designed a query (in design view) that calls my random function (Randomize statement followed by RND).

- If I run this query from the query window everything works fine and the random numbers do not repeat themselves BUT if I call the query from a button on a form the results are different! The random numbers repeat themselves.

This seems to make no logical sence but it is happening.

Thanks,

Chris
 
I've had this in the past. If you call randomize on startup the numbers repeat. But if you stop execution and wait for the user to do something and then randomize your random numbers should be random. Something to do with randomize creating numbers based a seed which is based on how long the program has been executing or something? Buggered if I know.
 
Thanks,

Unfortunately I can't stop execution each time the function is run. I'll have to find a new random function because I don't feel comfortable with this one...

Chris
 
How are you randomising?

As far as I know, the randomise function, as Hellferret says, is an algorhythm based on a 'seed' number. I guess you need to put the seed in at the last possible moment.

Could you put a randomise on the button code?

I normally use the system time to seed a random number, as it changes all the time. Without knowing exactly what you are doing, perhaps you could tweak this into your command button somewhere:

Dim seed
seed = Right(Time$, 2)
Randomize seed

This will start the random number from the seconds on your system time, which should be fairly random. If not random enough, you could make your own algorythm based on that to increase the permutations.
 
Thank you!

I put the randomize statment in the button code and it seems to have fixed the problem.

The button has the randomize and then calls the query that uses the random function. I'm not positive that the randomize statement is carrying over to the function but it seems to be ok.

I had originally and inappropriately put randomize statement in the function so a new seed was being used for each record that got a random number.

Thanks again,

Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top