tinyjo: (webdesigner - chez geek)
Emptied of expectation. Relax. ([personal profile] tinyjo) wrote2003-04-11 01:42 pm

Not random enough.

I'm putting in a random quote on my journal and friends pages and I'm having a little problem getting it random enough. I couldn't get the SQL server rand() function to work in Access, so I'm using VBs Rnd function to give me a number between zero and 1 which I then use to pick out one of the 115 quotes in my db. So far so good, except that it always seems to come up with the same quote. The seed I'm using for Rnd is Day Month Year Hour Minute Second. I'm lazy so I haven't checked whether it's always generating the same number or it's just the first couple of decimal places which are always the same, but either way, not helpful. Any suggestions?

In other weirdness, last week, no asp page which accessed the database would load from my local server - it just gave me an error message when I tried to open the db connection. Today, as I found out when I went to check the error message to ask you guys about it, it's fine. Who can fathom the ways of IIS?

[identity profile] soulsong.livejournal.com 2003-04-11 06:01 am (UTC)(link)
Why not call Randomize to initialise the seed based on the system timer, then call Rnd without an argument?

"Before calling Rnd, use the Randomize statement without an argument to initialize the random-number generator with a seed based on the system timer."

[identity profile] tinyjo.livejournal.com 2003-04-11 06:22 am (UTC)(link)
Oops - forgot to say that I tried that and got a similar result (i.e. always the same quote, but not the one I'm getting with the seed I'm using now).

Re:

[identity profile] soulsong.livejournal.com 2003-04-11 06:30 am (UTC)(link)
Sounds like you've got a bug 'elsewhere'.