• 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: Best way to get a non-repeating random number?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Best way to get a non-repeating random number?


  • Subject: Re: Best way to get a non-repeating random number?
  • From: "Luca C." <email@hidden>
  • Date: Tue, 14 Apr 2009 01:44:20 +0200

This isn't objc related, but mostly c related.  In order to get a random int
you may want to use the rand() function.  rand() returns a number between 0
and RAND_MAX, and you have to initialize this random generator by calling
srand().  You can put every (unsigned) value you want in there, though in
general it's used passing (unsigned)time(NULL) as parameter.  This way
you'll always get a different int.

2009/4/14 Eric E. Dolecki <email@hidden>

> I'd like to make sure a new random (int) number doesn't equal the previous.
> In ActionScript 3 I could just run a little while loop check against the
> previous value. So while it wasn't equal to the last it would be used. So
> this isn't using an Array by any means for anything.
> What's the best way to do this in Obj-C? The same way in AS3? I just want
> to
> make sure I set it correctly.


--
--Luca C.
_______________________________________________

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

  • Follow-Ups:
    • Re: Best way to get a non-repeating random number?
      • From: Uli Kusterer <email@hidden>
References: 
 >Best way to get a non-repeating random number? (From: "Eric E. Dolecki" <email@hidden>)

  • Prev by Date: Re: Obvious NSSegmentedControl Bug?
  • Next by Date: Re: Best way to get a non-repeating random number?
  • Previous by thread: Best way to get a non-repeating random number?
  • Next by thread: Re: Best way to get a non-repeating random number?
  • Index(es):
    • Date
    • Thread