Page 1 of 1

ramdom RND

Posted: Wed Apr 07, 2021 1:55 am
by Fernando Perez
Cicciocb, It seems that "rdn (number)" returns only values between 0 and number-1, not between 0 and number:

Code: [Local Link Removed for Guests]

DIM frecuency(7)
timer0 100, random
wait

random:
  r = rnd(7) ' Returns a random number in the range from 0 to 7
  frecuency(r) = frecuency(r) + 1
  iteration = iteration + 1
  if iteration = 100 then
    for i = 0 to 7
      result$ = result$ + str$(frecuency(i)) + " "
    next i
    wlog result$
    iteration = 0
    result$ = ""
  end if
return

Re: ramdom RND

Posted: Wed Apr 07, 2021 7:29 am
by cicciocb
HI Fernando,
this is normal as the final value is not inclusive.
So RND(5) gives values from 0 to 4 (range of 5).

This is as the visual basic rnd() function that returns a value less than 1 but greater than or equal to zero.

Some references

https://www.ibm.com/docs/en/iis/11.5?to ... d-function

https://docs.microsoft.com/en-us/office ... d-function

Re: ramdom RND

Posted: Wed Apr 07, 2021 11:43 am
by Fernando Perez
You're right, it's something I didn't remember.
But it is that in the help of Annex she says:
image.png
And it can confuse language novices (or not so novices).
Notice that the link you put in the first place says textually:
"expression evaluates to the total number of integers, including 0, from which the random number can be selected. That is, if n is the value of expression, the random number is generated from the numbers 0 through (n - 1)."
I think this should be clarified in the Annex help.
It has nothing to do with the subject, but for those interested in BASIC Archeology, I have found this:
https://myrapidq.it/public/BASIC_Oct64.pdf

Re: ramdom RND

Posted: Mon Apr 19, 2021 6:16 pm
by cicciocb
Thanks Fernando.
I updated the doc (will be available in the next version)