Page 3 of 5
Re: Documentation problems
Posted: Sun Nov 18, 2018 10:47 pm
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"?
Re: Documentation problems
Posted: Sun Nov 18, 2018 11:43 pm
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
Re: Documentation problems
Posted: Mon Nov 19, 2018 10:07 pm
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
Re: Documentation problems
Posted: Tue Nov 20, 2018 12:55 am
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
Re: Documentation problems
Posted: Tue Nov 20, 2018 6:31 pm
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.
Re: Documentation problems
Posted: Tue Nov 20, 2018 11:10 pm
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.
Re: Documentation problems
Posted: Thu Nov 22, 2018 12:14 pm
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.
Re: Documentation problems
Posted: Thu Nov 22, 2018 2:56 pm
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.
Re: Documentation problems
Posted: Thu Nov 22, 2018 7:24 pm
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.
Re: Documentation problems
Posted: Thu Nov 22, 2018 10:15 pm
by emeck
Thanks Andreas.