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"?
PowerBook 5.2 MorphOS 3.15
PowerBook 5.8 MorphOS 3.15
Amiga 1200 BPPC/BVision AOS4.1 FE
PowerBook 5.8 MorphOS 3.15
Amiga 1200 BPPC/BVision AOS4.1 FE
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
PowerBook 5.2 MorphOS 3.15
PowerBook 5.8 MorphOS 3.15
Amiga 1200 BPPC/BVision AOS4.1 FE
PowerBook 5.8 MorphOS 3.15
Amiga 1200 BPPC/BVision AOS4.1 FE
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: 4441
 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.
PowerBook 5.2 MorphOS 3.15
PowerBook 5.8 MorphOS 3.15
Amiga 1200 BPPC/BVision AOS4.1 FE
PowerBook 5.8 MorphOS 3.15
Amiga 1200 BPPC/BVision AOS4.1 FE

 Posts: 368
 Joined: Fri May 15, 2015 5:15 pm
 Location: Waterville, Minnesota 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.
I'm on registered MorphOS using FlowStudio.
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.
PowerBook 5.2 MorphOS 3.15
PowerBook 5.8 MorphOS 3.15
Amiga 1200 BPPC/BVision AOS4.1 FE
PowerBook 5.8 MorphOS 3.15
Amiga 1200 BPPC/BVision AOS4.1 FE
 airsoftsoftwair
 Posts: 4441
 Joined: Fri Feb 12, 2010 2:33 pm
 Location: Germany
 Contact:
Re: Documentation problems
Thanks Andreas.
PowerBook 5.2 MorphOS 3.15
PowerBook 5.8 MorphOS 3.15
Amiga 1200 BPPC/BVision AOS4.1 FE
PowerBook 5.8 MorphOS 3.15
Amiga 1200 BPPC/BVision AOS4.1 FE