Re: Random Number
Re: Random Number
- Subject: Re: Random Number
- From: Daniel Waylonis <email@hidden>
- Date: Thu, 28 Feb 2002 13:38:39 -0800
On Thursday, February 28, 2002, at 11:57 AM, Jens Bauer wrote:
>
Hi Shaun,
>
>
On Thu, 28 Feb, 2002, Shaun Chu <email@hidden> wrote:
>
>
> Sorry if this sounds like a dumb question, but how do I get a
>
> truly random
>
> number in Cocoa?
>
>
Unfortunately, the only computer that had a true random
>
generator was the
>
Sinclair ZX81.
>
This machine used processor-noise for random-generation, and it worked
>
very well.
>
>
If you need something less sophisticated, you can use rand()
>
which is the
>
worst choice,
>
or you could grab a timer now and then, insert some of the
>
low-order bits
>
into a longword, multiply this by 31415927, keep this as the
>
seed value,
>
and return (the seed bitshifted 8 to the right)
>
>
Finally, you could go and use the Cocoa API's random, which would
>
probably be preferrable.
Hi,
You might check out the man page for random, srandom, urandom,
and prandom using the command "man 4 random".
They're all "devices" (e.g., /dev/urandom) that you can open up
for reading how ever many bytes you want to get your random
number.
Also, you can take a look at the standard C library stuff: "man
3 random"
Dan
______________________________________________________________________
Dan Waylonis email@hidden
Software Guy
http://www.nekotech.com
nekotech SOFTWARE 650.964.2490 Voice / Fax
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.