Documentation problems

Report any Hollywood bugs here
User avatar
emeck
Posts: 94
Joined: Fri Apr 03, 2015 3:17 pm

Re: Documentation problems

Post by emeck »

Hello, in HW guide Rnd() funtion says:

Generates a random integer number in the range of 0 to "range" (inclusive).

I suppose it should say "exclusive" or "non inclusive"?
PowerBook 5.2 MorphOS 3.13
PowerBook 5.8 MorphOS 3.13
Amiga 1200 BPPC/BVision AOS4.1 FE

Tipsi
Posts: 17
Joined: Sun Feb 14, 2010 6:06 pm

Re: Documentation problems

Post by Tipsi »

Hi emeck

History V7.1 says the following:

- Fix [Doc]: The range parameter in the Rnd() function was documented as being exclusive whereas it is inclusive in reality

Griessli
Tipsi

User avatar
emeck
Posts: 94
Joined: Fri Apr 03, 2015 3:17 pm

Re: Documentation problems

Post by emeck »

@Tipsi

ok, I think I get it now. If I use Rnd(75) it will return a value out of 75 possibilities, from 0 to 74. Right?

Regards,
emeck
PowerBook 5.2 MorphOS 3.13
PowerBook 5.8 MorphOS 3.13
Amiga 1200 BPPC/BVision AOS4.1 FE

Tipsi
Posts: 17
Joined: Sun Feb 14, 2010 6:06 pm

Re: Documentation problems

Post by Tipsi »

Hi emeck

No, Rnd(75) generates a random integer number in the range
of 0 to 75 (inclusive 75; 76 possibilities).

Griessli
Tipsi

User avatar
airsoftsoftwair
Posts: 4368
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Documentation problems

Post by airsoftsoftwair »

@emeck:

Looking at the example in the Rnd() documentation should make it clear:
num=Rnd(49)
Well, I cannot predict what value num will receive. I can only say that it will not be greater than 49 and not smaller than zero.
This means that "num" can indeed be 49 but not 50.

User avatar
emeck
Posts: 94
Joined: Fri Apr 03, 2015 3:17 pm

Re: Documentation problems

Post by emeck »

@airsoftsoftwair

That is what I understood at first but seems to work different for me. Maybe some newbie mistake.

Consider this simple example:

Code: Select all

EscapeQuit(True)

For i = 1 To 1000
    DebugPrint(Rnd(49))
Next

End()

Repeat
    WaitEvent()
Forever  
Running it several times it never prints 49, top number is 48.
With Rnd(5) it prints 0s, 1s, 2s, 3s and 4s, never 5.
With Rnd(3) it prints 0s, 1s and 2s, never 3.
With Rnd(2) it prints 0s, and 1s, never 2.
With Rnd(1) it prints all 0s.

This is with HW7.1 and MOS 3.11.
PowerBook 5.2 MorphOS 3.13
PowerBook 5.8 MorphOS 3.13
Amiga 1200 BPPC/BVision AOS4.1 FE

SamuraiCrow
Posts: 319
Joined: Fri May 15, 2015 5:15 pm
Location: Waterville, Minnesota USA

Re: Documentation problems

Post by SamuraiCrow »

@Emeck
The value clamping on a random number generator is a remainder of a division. It will be greater or equal to zero but strictly less than the maximum value passed in.
I'm on registered MorphOS using FlowStudio.

User avatar
emeck
Posts: 94
Joined: Fri Apr 03, 2015 3:17 pm

Re: Documentation problems

Post by emeck »

@SamuraiCrow
The value clamping on a random number generator is a remainder of a division. It will be greater or equal to zero but strictly less than the maximum value passed in.
Yes, which was the point in my original post. If Rnd(3) will generate values from 0 to 2, it is not inclusive for the value passed to the function.

If I try instead RndStrong(#INTEGER,3) then I get values from 0 to 3; so in this case it is incluve.
PowerBook 5.2 MorphOS 3.13
PowerBook 5.8 MorphOS 3.13
Amiga 1200 BPPC/BVision AOS4.1 FE

User avatar
airsoftsoftwair
Posts: 4368
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Documentation problems

Post by airsoftsoftwair »

Ok, after investigating this issue I have to admit that emeck is right. It is broken, or rather the documentation is broken, both for Rnd() and RndF(). Rnd() is exclusive and RndF() will never return 1. I'll fix this in the doc for the next release.

User avatar
emeck
Posts: 94
Joined: Fri Apr 03, 2015 3:17 pm

Re: Documentation problems

Post by emeck »

Thanks Andreas.
PowerBook 5.2 MorphOS 3.13
PowerBook 5.8 MorphOS 3.13
Amiga 1200 BPPC/BVision AOS4.1 FE

Post Reply