Bill Allombert on Tue, 25 Sep 2012 14:56:12 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Question about random.


On Tue, Sep 25, 2012 at 12:04:08PM +0100, Omar Al Hammal wrote:
>   Dear all,
> 
>  I am writing because I am fairly new to gp/pari and think to have found a mistake in some codes I have to use. I would like to have some opinions to know whether or not it indeed is a mistake. 
> The corrected version I now work with is :
> 
> longestint=2^31;
> longestintm=2^31-1;
> 
> specieslabelanc = vector(J);
>  \\ with a<J
> z = ceil((random(longestintm)+1)/longestint * (a - 1));
>  specieslabelind[n] = specieslabelanc[z];

Hello Omar,

This seems uselessly complicated. 
If you want a random number between 1 and a, you can just do
z = 1 + random(a-1);

Cheers,
Bill.