• 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: Generating random numbers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Generating random numbers


  • Subject: Re: Generating random numbers
  • From: Mahaboob <email@hidden>
  • Date: Thu, 06 Aug 2009 17:38:47 +0530
  • Thread-topic: Generating random numbers

Yeah, you are right.
I did my own code and is working well for me.
My code is :

    srandom(time(NULL));
    BOOL val;
    val = FALSE;
    array = [[NSMutableArray alloc]initWithCapacity:15];
    firstNo = random()+1;
    [array addObject:[NSNumber numberWithInt:firstNo]];
    for(i=1;i<15;i++){
        firstNo = random()+1;
        for(j=0;j<[array count];j++){

            if((firstNo == [[array objectAtIndex:j]intValue] )){
                i--;
                val = TRUE;
                break;
            }

        }
        if(val){
            val = FALSE;
            continue;
        }
        else{

            [array addObject:[NSNumber numberWithInt:firstNo]];

        }
    }


Thanks


On 8/6/09 1:50 PM, "Alastair Houghton" <email@hidden> wrote:

> On 6 Aug 2009, at 05:59, Mahaboob wrote:
>
>> Thanks.
>> It is working well.
>
> I'll say again, off-list, you probably don't want to use Agha Khan's
> code; it generates biased results, which are bad in almost all
> applications.  Take a look at the Wikipedia article I pointed you at,
> here, for (a) an algorithm that works, and (b) some notes on
> generating random numbers:
>
>    <http://en.wikipedia.org/wiki/Knuth_shuffle>
>
> Kind regards,
>
> Alastair.
>
> --
> http://alastairs-place.net
>
>
>


_______________________________________________

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: Generating random numbers
      • From: Jeremy Pereira <email@hidden>
  • Prev by Date: Re: defining NSColor constants
  • Next by Date: Accessor methods in Category
  • Previous by thread: Re: Generating random numbers
  • Next by thread: Re: Generating random numbers
  • Index(es):
    • Date
    • Thread