Re: Generating random numbers
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