|
|
|
|
|
|
| |
| |
|
|
|
|
| |
| |
|
|
How do I calculate a random integer between n and p, inclusively?
Thanks
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Mike Horvath wrote:
> How do I calculate a random integer between n and p, inclusively?
>
>
> Thanks
#declare RSeed = seed(1);
#declare RandomNumber = n + rand(RSeed) * (p - n);
--
Ger
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Ger wrote:
> Mike Horvath wrote:
>
>> How do I calculate a random integer between n and p, inclusively?
>>
>>
>> Thanks
> #declare RSeed = seed(1);
>
#declare RandomNumber = int(n + rand(RSeed) * (p - n));
--
Ger
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
On 1/31/2016 9:06 PM, Ger wrote:
> Mike Horvath wrote:
>
>> How do I calculate a random integer between n and p, inclusively?
>>
>>
>> Thanks
> #declare RSeed = seed(1);
>
> #declare RandomNumber = n + rand(RSeed) * (p - n);
>
That results in a float, not an integer.
Mike
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Am 01.02.2016 um 02:55 schrieb Mike Horvath:
> How do I calculate a random integer between n and p, inclusively?
floor( rand(R)*((p-n)+1) + 0.5 )
should do the trick
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Mike Horvath wrote:
> On 1/31/2016 9:06 PM, Ger wrote:
>> Mike Horvath wrote:
>>
>>> How do I calculate a random integer between n and p, inclusively?
>>>
>>>
>>> Thanks
>> #declare RSeed = seed(1);
>>
>> #declare RandomNumber = n + rand(RSeed) * (p - n);
>>
>
> That results in a float, not an integer.
>
>
> Mike
I corrected it.
--
Ger
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Am 01.02.2016 um 03:10 schrieb clipka:
> Am 01.02.2016 um 02:55 schrieb Mike Horvath:
>> How do I calculate a random integer between n and p, inclusively?
>
> floor( rand(R)*((p-n)+1) + 0.5 )
>
> should do the trick
... provided you figure out that you need to add n ;)
Oops.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Yes, there are two functions to convert a float to a close-by integer:
1. Floor
If the float is, let's say, "11.4676475" (could be a multiplication of a
"rand" random result), floor returns "11" (the next integer BELOW that
float).
2. Ceil(ing)
If the float is, let's say, "11.4676475" (could be a multiplication of a
"rand" random result), floor returns "12" (the next integer ABOVE that
float).
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
On 1-2-2016 3:10, clipka wrote:
> Am 01.02.2016 um 02:55 schrieb Mike Horvath:
>> How do I calculate a random integer between n and p, inclusively?
>
> floor( rand(R)*((p-n)+1) + 0.5 )
>
> should do the trick
>
Why not this: int(RRand(n,p,R))
--
Thomas
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
On 02/01/2016 03:06 AM, Thomas de Groot wrote:
> On 1-2-2016 3:10, clipka wrote:
>> Am 01.02.2016 um 02:55 schrieb Mike Horvath:
>>> How do I calculate a random integer between n and p, inclusively?
>>
>> floor( rand(R)*((p-n)+1) + 0.5 )
>>
>> should do the trick
>>
>
> Why not this: int(RRand(n,p,R))
>
RRand(Min,Max,RandSeededStream) from rand.inc. To get the inclusive part
of the request I think we need:
int(RRand(n,p+(1-1e-6),R))
or
floor(RRand(n,p+(1-1e-6),R))
Bill P.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |