• 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: repeatable random numbers in an object
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

re: repeatable random numbers in an object


  • Subject: re: repeatable random numbers in an object
  • From: "Mr. George Warner" <email@hidden>
  • Date: Wed, 17 Jun 2009 08:51:26 -0700

On Wed, 17 Jun 2009 22:33:50 +0800, Roland King <email@hidden> wrote:
> I need to generate repeatable sequences of random numbers for a game.
> For each level I give it the seed and want the level to unfold the
> same way it did before. I can guarantee that the calls to any random
> function will be in exactly the same order, so provided I get the same
> sequence out of the random generator, I'm good.


> First thought was to use srand() [ yes it's a bad random number
> generator but it's good enough for what want ] however it's global and
> it's quite possible I'll have more than one 'level' running at the
> same time. So I need an object which I can give a seed to and will
> generate random numbers from that seed, and I need it to interoperate
> independently of any other object of the same type being queried for
> numbers.


term> man rand_r
...
The rand_r() function provides the same functionality as rand(). A pointer to the context value seed must be
supplied by the caller.


The "pointer to the context value seed" can be a per-thread variable so that different contexts don't interfere with each other. ;-)

--
Enjoy,
George Warner,
Schizophrenic Optimization Scientist
Apple Developer Technical Support (DTS)

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: Group CGAffineTransform Animations?
  • Next by Date: Re: advice on background process
  • Previous by thread: Re: repeatable random numbers in an object
  • Next by thread: Re: repeatable random numbers in an object
  • Index(es):
    • Date
    • Thread