• 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: "Eric E. Dolecki" <email@hidden>
  • Date: Tue, 14 Apr 2009 16:32:30 -0400

My apologies - what  I meant to type was that I AM doing this:

int tmp = (arc4random())+1;

while (tmp == activeTarget) {

  tmp = (arc4random())+1;

}

activeTarget = tmp;


This is for a game, so it's not very critical or anything. Someone told me
that I might want to avoid a while loop at all by doing something like this:


int result = (arc4random()%9) + 1;

if (result >= activeTarget) ++result;

activeTarget = result;


That seems a little odd to me to do things that way - but I'm not really
sure.



On Tue, Apr 14, 2009 at 4:08 PM, Andrew Farmer <email@hidden> wrote:

> On 14 Apr 09, at 09:24, Eric E. Dolecki wrote:
>
>> to get back to my original question I'm not just doing this:
>>
> <snip>
>
> Then what are you doing? It'd really help to know what you're trying to
> accomplish here.
>
>


--
http://ericd.net
Interactive design and development
_______________________________________________

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: Greg Parker <email@hidden>
    • Re: Best way to get a non-repeating random number?
      • From: Peter Duniho <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>)
 >Re: Best way to get a non-repeating random number? (From: Uli Kusterer <email@hidden>)
 >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: Jean-Daniel Dupas <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: "Eric E. Dolecki" <email@hidden>)
 >Re: Best way to get a non-repeating random number? (From: Andrew Farmer <email@hidden>)

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