• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Random Number
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >Re: Random Number (From: Jens Bauer <email@hidden>)

  • Prev by Date: RE: Problems converting NSString path to FSSpec
  • Next by Date: Opacity in IB
  • Previous by thread: Re: Random Number
  • Next by thread: determining binary files from text
  • Index(es):
    • Date
    • Thread