Documentation problems
Re: Documentation problems
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"?
Generates a random integer number in the range of 0 to "range" (inclusive).
I suppose it should say "exclusive" or "non inclusive"?
Re: Documentation problems
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
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
Re: Documentation problems
@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
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
Re: Documentation problems
Hi emeck
No, Rnd(75) generates a random integer number in the range
of 0 to 75 (inclusive 75; 76 possibilities).
Griessli
Tipsi
No, Rnd(75) generates a random integer number in the range
of 0 to 75 (inclusive 75; 76 possibilities).
Griessli
Tipsi
 airsoftsoftwair
 Posts: 3022
 Joined: Fri Feb 12, 2010 2:33 pm
 Location: Germany
 Contact:
Re: Documentation problems
@emeck:
Looking at the example in the Rnd() documentation should make it clear:
Looking at the example in the Rnd() documentation should make it clear:
This means that "num" can indeed be 49 but not 50.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.
Re: Documentation problems
@airsoftsoftwair
That is what I understood at first but seems to work different for me. Maybe some newbie mistake.
Consider this simple example:
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.
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
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.

 Posts: 213
 Joined: Fri May 15, 2015 5:15 pm
 Location: Ft. Collins, Colorado USA
Re: Documentation problems
@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.
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.
Re: Documentation problems
@SamuraiCrow
If I try instead RndStrong(#INTEGER,3) then I get values from 0 to 3; so in this case it is incluve.
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.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.
If I try instead RndStrong(#INTEGER,3) then I get values from 0 to 3; so in this case it is incluve.
 airsoftsoftwair
 Posts: 3022
 Joined: Fri Feb 12, 2010 2:33 pm
 Location: Germany
 Contact:
Re: Documentation problems
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.