• 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: Seeding random() randomly
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Seeding random() randomly


  • Subject: Re: Seeding random() randomly
  • From: Michael Hall <email@hidden>
  • Date: Thu, 26 May 2011 21:26:19 -0500

On May 26, 2011, at 8:00 PM, Graham Cox wrote:

> I'm using random(), but every time I run my app I get the same sequence, despite having this code in my app delegate's -appDidFinishLaunching method. Clearly I'm not seeding it right, though I can't see why - I get a different value for seed every time. What gives?
>
>
> 	unsigned seed = (unsigned)([NSDate timeIntervalSinceReferenceDate] * 10000.0);
>
> 	NSLog(@"launched, seed = %ld", seed );
> 	srandom( seed );

	unsigned seed = (unsigned)([NSDate timeIntervalSinceReferenceDate] * 10000.0);
	sleep(2);
	unsigned seed2 = (unsigned)([NSDate timeIntervalSinceReferenceDate] * 9999.0);
	if (seed == seed2)
		NSLog(@"match %u %u",seed,seed2);
	else
		NSLog(@"mismatch %u %u",seed,seed2);

2011-05-26 21:24:23.339 SRandom[885:80f] match 4294967295 4294967295

_______________________________________________

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

References: 
 >Seeding random() randomly (From: Graham Cox <email@hidden>)

  • Prev by Date: Re: encoding of file names
  • Next by Date: Adding HTML data to the general pasteboard
  • Previous by thread: Re: Seeding random() randomly
  • Next by thread: Re: Seeding random() randomly
  • Index(es):
    • Date
    • Thread