Rnd() ignores the maximum value

Discussion in 'Questions (Windows Mobile)' started by Mistrel, Oct 13, 2007.

  1. Mistrel

    Mistrel Member

    If you run this example you'll see that rnd() never returns 1.

    Sub App_Start
    x=0
    Do
    n=Rnd(0,1)
    If n=0 Then
    Msgbox(n)
    Else
    Msgbox(n)
    End If
    Loop Until x=1
    End Sub
     
  2. Erel

    Erel Administrator Staff Member Licensed User

  3. Mistrel

    Mistrel Member

    Sorry. I admit that I skimmed over the documentation for rnd() (as short as it was). I've never seen a rnd function that ignores the upper limit before and assumed wrong. I was convinced this was a bug.

    :sign0013:
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    No problem ;)
    This is how it behaves in C# and VB .Net.
     
  5. Mistrel

    Mistrel Member

    Really? That's so confusing. o.o
     
  6. Cableguy

    Cableguy Expert Licensed User

    In the old days, in my zx spectrum ++, rnd only returned a value between 0 and....1, except for the ....1 so we ould get decimal of 0.1,0.2,....etc and we couldnt even state the max or min values.... now that was confusing....:signOops:
     
    Last edited: Oct 14, 2007
  7. specci48

    specci48 Well-Known Member Licensed User

    ... max values were possible ...

    10 LET A = INT(RND*N)

    ... results for A are values from 0 to N-1 ... :)

    specci48
     
Loading...