RAN() misbehaving
#1
Description:
The ran-function returns a random number. If no argument is given, the number returned is in the range from 0 to 1; where only 0 is a possible value; 1 will never be returned. If an argument is supplied, the number returned will be in the range from 0 up to this argument, whereas this argument itself is not a possible return value.


OK, so RAN(7) is supposed to give me a random number between 0 and 6.9999. This is how the command has worked in every version of BASIC I've ever seen. It seems to be broken in yab.

Code:
~/projects/DailyHaiku/binder> touch ran.bas
~/projects/DailyHaiku/binder> echo "print ran(7)">ran.bas
~/projects/DailyHaiku/binder> cat ran.bas
print ran(7)
~/projects/DailyHaiku/binder> yab ran.bas
2.04283
~/projects/DailyHaiku/binder> yab ran.bas
2.04294
~/projects/DailyHaiku/binder> yab ran.bas
2.04299
~/projects/DailyHaiku/binder> yab ran.bas
2.04305
~/projects/DailyHaiku/binder> yab ran.bas
2.04305
~/projects/DailyHaiku/binder> yab ran.bas
2.0431
~/projects/DailyHaiku/binder> yab ran.bas
2.04316
~/projects/DailyHaiku/binder> yab ran.bas
2.04327
~/projects/DailyHaiku/binder> yab ran.bas
2.04332

Yes, those are technically random numbers. But nowhere near the range the command is supposed to give.

yab 1.7.5 running on Haiku hrev49371

Let's increase that seed number to 14

Code:
~/projects/DailyHaiku/binder> rm ran.bas
~/projects/DailyHaiku/binder> touch ran.bas
~/projects/DailyHaiku/binder> echo "print ran(14)">ran.bas
~/projects/DailyHaiku/binder> /bin/yab ran.bas
4.22032
~/projects/DailyHaiku/binder> /bin/yab ran.bas
4.22086
~/projects/DailyHaiku/binder> /bin/yab ran.bas
4.22097
~/projects/DailyHaiku/binder> /bin/yab ran.bas
4.22108
~/projects/DailyHaiku/binder> /bin/yab ran.bas
4.22119
~/projects/DailyHaiku/binder> /bin/yab ran.bas
4.2213
~/projects/DailyHaiku/binder> /bin/yab ran.bas
4.22141

The same thing happens with an old (1.7) version of yab, so the problem either is in the underlying OS, or I am not understanding the documentation.

RAN() without a seed number works as expected so as a workaround we can use (RAN()) * 7

In fact it is worse: if you try

for f = 1 to 10
print ran()
next

and run it a few times the first one always seems to start with 0.3, and only after that does it start to look random at all.
Reply


Messages In This Thread
RAN() misbehaving - by clasqm - 07-06-2015, 01:04 PM
RE: RAN() misbehaving - by bbjimmy - 07-06-2015, 01:43 PM
RE: RAN() misbehaving - by clasqm - 07-07-2015, 10:52 AM
RE: RAN() misbehaving - by bbjimmy - 07-08-2015, 03:03 PM
RE: RAN() misbehaving - by lorglas - 08-23-2015, 07:08 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)
Free Web Hosting