|
|
|
|
|
|
| |
| |
|
|
|
|
| |
| |
|
|
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
|
|
| |
| |
|
|
|
|
| |
| |
|
|
On 1-2-2016 13:19, William F Pokorny wrote:
> 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.
Are the Min and Max not inclusive by default? I always got that impression.
--
Thomas
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
On 02/01/2016 07:21 AM, Thomas de Groot wrote:
> On 1-2-2016 13:19, William F Pokorny wrote:
>> 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.
>
> Are the Min and Max not inclusive by default? I always got that impression.
>
For floats yes.
Mike wants integers so we are using int() or floor(). Seems to me the
only way we can get the Max integer value is if the rand() function
returns exactly 1.0 - which it will pretty much never do, but might.
The +(1-1e-6) makes it so we get the Max integer value only one
millionth less often than ideally we should.
We could specify a max integer 1 larger than we really want for p, but
then rand() will be a troublemaker and give us that 1.0 value in our
scene.
Bill P.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |