Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

random numbers

1 view
Skip to first unread message

Roman Mashak

unread,
Aug 11, 2006, 1:59:51 AM8/11/06
to
Hello,

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


Richard Heathfield

unread,
Aug 11, 2006, 2:30:19 AM8/11/06
to
Roman Mashak said:

> 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)

toby

unread,
Aug 11, 2006, 3:43:03 AM8/11/06
to
Roman Mashak wrote:
> Hello,
>
> 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.

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

Roman Mashak

unread,
Aug 11, 2006, 4:30:52 AM8/11/06
to
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.

??>> 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.

Richard Heathfield

unread,
Aug 11, 2006, 11:10:03 AM8/11/06
to
Roman Mashak said:

> 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.

Andrey Tarasevich

unread,
Aug 11, 2006, 7:39:59 PM8/11/06
to
Roman Mashak wrote:
> 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.
> ...

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

goose

unread,
Aug 12, 2006, 6:08:26 AM8/12/06
to
Roman Mashak wrote:
> 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.
>

Picking the least used one is an even better method
than RNG for load-balancing.

goose,

0 new messages