Documentation problems

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

Re: Documentation problems

Post by emeck » Sun Nov 18, 2018 10:47 pm

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.12
PowerBook 5.8 MorphOS 3.12
Amiga 1200 BPPC/BVision AOS4.1 FE

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

Re: Documentation problems

Post by Tipsi » Sun Nov 18, 2018 11:43 pm

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: 79
Joined: Fri Apr 03, 2015 3:17 pm

Re: Documentation problems

Post by emeck » Mon Nov 19, 2018 10:07 pm

@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.12
PowerBook 5.8 MorphOS 3.12
Amiga 1200 BPPC/BVision AOS4.1 FE

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

Re: Documentation problems

Post by Tipsi » Tue Nov 20, 2018 12:55 am

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: 3162
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Documentation problems

Post by airsoftsoftwair » Tue Nov 20, 2018 6:31 pm

@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: 79
Joined: Fri Apr 03, 2015 3:17 pm

Re: Documentation problems

Post by emeck » Tue Nov 20, 2018 11:10 pm

@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.12
PowerBook 5.8 MorphOS 3.12
Amiga 1200 BPPC/BVision AOS4.1 FE

SamuraiCrow
Posts: 237
Joined: Fri May 15, 2015 5:15 pm
Location: Ft. Collins, Colorado USA

Re: Documentation problems

Post by SamuraiCrow » Thu Nov 22, 2018 12:14 pm

@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.

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

Re: Documentation problems

Post by emeck » Thu Nov 22, 2018 2:56 pm

@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.12
PowerBook 5.8 MorphOS 3.12
Amiga 1200 BPPC/BVision AOS4.1 FE

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

Re: Documentation problems

Post by airsoftsoftwair » Thu Nov 22, 2018 7:24 pm

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: 79
Joined: Fri Apr 03, 2015 3:17 pm

Re: Documentation problems

Post by emeck » Thu Nov 22, 2018 10:15 pm

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

Post Reply