I need to generate randomly numbers from the range [1..4] on linux 2.4.20
kernel. What are the most reliable methods to achive this, apart from
rand()/srand() and reading /dev/random ?
I heard someone use process ID and gettimeofday() output (especially
'seconds' field), but how I don't know.
I appreciate any advice, thanks !
With best regards, Roman Mashak. E-mail: m...@tusur.ru
> Hello,
>
> I need to generate randomly
How randomly?
> numbers from the range [1..4] on linux 2.4.20 kernel.
How often?
> What are the most reliable methods to achive this, apart from
> rand()/srand() and reading /dev/random ?
Investigate /dev/urandom
> I heard someone use process ID and gettimeofday() output (especially
> 'seconds' field), but how I don't know.
By XORing them together, like as not.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
This is for seeding? Or if you want entropy sources, use /dev/urandom,
egd etc as Richard suggests: See 'man random',
http://egd.sourceforge.net/ ,
http://en.wikipedia.org/wiki/Hardware_random-number_generator ,
http://www.macfergus.com/pub/yarrow.html
Some alternative PRNGs are Mersenne Twister, Marsaglia's suggestions
here
http://groups.google.com/group/comp.soft-sys.math.mathematica/msg/95a94c3b2aa5f077
or Jenkins' generators http://www.burtleburtle.net/bob/rand/isaac.html
??>> Hello,
??>>
??>> I need to generate randomly
RH> How randomly?
The device I'm working on chooses one of 4 RF channels. My intention is to
achive sort of load balancing through randomly picked channels. And I assume
that good RNG may be better then round-robin algorithm in my case.
??>> numbers from the range [1..4] on linux 2.4.20 kernel.
RH> How often?
It may vary: from once for day to every 2 hours.
??>> What are the most reliable methods to achive this, apart from
??>> rand()/srand() and reading /dev/random ?
RH> Investigate /dev/urandom
Perhaps you meant /dev/random since it gives higher quality of randomness?
??>> I heard someone use process ID and gettimeofday() output (especially
??>> 'seconds' field), but how I don't know.
RH> By XORing them together, like as not.
Now I think process ID and time stamps are not suitable for me, cause their
nature isn't random, but rather predictable.
> Hello, Richard!
> You wrote on Fri, 11 Aug 2006 06:30:19 +0000:
>
> ??>> Hello,
> ??>>
> ??>> I need to generate randomly
>
> RH> How randomly?
> The device I'm working on chooses one of 4 RF channels. My intention is to
> achive sort of load balancing through randomly picked channels. And I
> assume that good RNG may be better then round-robin algorithm in my case.
If that's all you want it for, then it doesn't make a halfpenny of
difference what you use. rand() will be fine.
For such a purpose there's abosolutely no need to use a "good" RNG. Any
half-decent pseudo-RNG will work perfectly fine.
--
Best regards,
Andrey Tarasevich
Picking the least used one is an even better method
than RNG for load-balancing.
goose,