• 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: Uli Kusterer <email@hidden>
  • Date: Tue, 14 Apr 2009 01:57:19 +0200

On 14.04.2009, at 01:44, Luca C. wrote:
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.


No you won't. It's a *random* number generator. The seed simply means you get a different sequence of random numbers. However, random really means RANDOM. I.e. it's perfectly possible to get the same number three times in a row during a sequence. That would still be random.

I think it would be best if Eric told us what he's trying to do. For example, in some cases, (e.g. sorting) you actually want to build a new list and shuffle that by returning random numbers from your sort function. In that case, since your list only contains each item once, and your random numbers only affect their order, it's perfectly OK to just return a random number. You'll still get a shuffled list with each item only once.

OTOH, in other cases, you might actually have to do the looping thing and just keep asking for a new random number until you get one that isn't the previous number.

Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de





_______________________________________________

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: "Luca C." <email@hidden>
    • Re: Best way to get a non-repeating random number?
      • From: Michael Ash <email@hidden>
    • Re: Best way to get a non-repeating random number?
      • From: WT <email@hidden>
References: 
 >Best way to get a non-repeating random number? (From: "Eric E. Dolecki" <email@hidden>)
 >Re: Best way to get a non-repeating random number? (From: "Luca C." <email@hidden>)

  • Prev by Date: Re: Best way to get a non-repeating random number?
  • Next by Date: Re: Exit an Application
  • Previous by thread: Re: 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