• 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: Jens Bauer <email@hidden>
  • Date: Thu, 28 Feb 2002 20:57:05 +0100

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.


Love,
Jens

--
Jens Bauer, Faster Software.
-Let's make the World better, shall we ?
_______________________________________________
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.

  • Follow-Ups:
    • Re: Random Number
      • From: Daniel Waylonis <email@hidden>
References: 
 >Random Number (From: Shaun Chu <email@hidden>)

  • Prev by Date: Re: NSView Names
  • Next by Date: Re: launchApplication and window deselection
  • Previous by thread: Re: Random Number
  • Next by thread: Re: Random Number
  • Index(es):
    • Date
    • Thread