POV-Ray : Newsgroups : povray.general : Random integer : Re: Random integer Server Time
31 Oct 2024 20:18:26 EDT (-0400)
  Re: Random integer  
From: Thomas de Groot
Date: 2 Feb 2016 02:42:08
Message: <56b05dd0$1@news.povray.org>
On 1-2-2016 16:30, William F Pokorny wrote:
> 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.
>

OK. Got it. Thanks a lot!

-- 
Thomas


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.