[ILUG-BOM] random no generation issues
Thu Mar 13 12:27:37 IST 2003
Hi to generate the random number I would still suggest
that you use rand() function given by C and use it
nicely i.e effectively using seed so that you dont
get same no again and again. I used to use it in my
good old collage days. And this function is still
being used in most of the software even today
Second method is to divide a second, now whenever you
press any key find out which milisecond part of that
second take out its unit place and you get a brand new
random number. This technique is used in developing an
arcade game jackpot las vagas style
Third method is to use the system generated datetime
stamp multiply the each individual number with each
other and take out its unit place of the resultant
For some strange reason we have always been using
time-space for finding out the unique random number
You Last full resort should be
Get the no of ticks that your processor gives in a
particular duration say 1 sec and get out its last
unit digit, obviously your random number generation
has to do with your processor speed
--- Philip S Tellis <philip at konark.ncst.ernet.in>
> On Wed, 12 Mar 2003, Manish Jethani wrote:
> > Ok, I get the idea. Use rand() instead, for
> portability. And
> > you have to seed the random no. generator with,
> say, the current
> > time. Seed it using srandom((unsigned)
> time(NULL)) before any
> > calls to random().
> Althought that is what I do, someone once said that
> it's a bad idea to
> seed the random number generator with the system
> > > or does someone have a better idea of generating
> random nos?
> > Yes, read the manual for random(3), srandom(3),
> rand(3), etc.
> Read Seminumerical Analysis by the Don. It'll pass
> on some insights
> into the theory of random number generation.
> Remember, all generated random numbers are just
> pseudo random. If you
> really want a random number, stick your finger in
> the air, pick the
> molecule that lands in the very centre of the tip of
> your finger, and
> measure its vibration. Ensure it stays at the
> centre of your finger at
> this point.
> Woman on Street: Sir, you are drunk; very, very
> Winston Churchill: Madame, you are ugly; very, very
> I shall be sober in the morning.
Do you Yahoo!?
Yahoo! Web Hosting - establish your business online
More information about the Linuxers