Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Not so much a bug, as slow!
#16
Just to complement my previous answer... My suggestion for INTRND(n) was that the compiler would generate an Assembly code equivalent to this:

Code:
'Generate random number between 0 and n-1
function INTRND(n AS UINTEGER) AS UINTEGER
    DIM result AS UINTEGER
    DIM bits AS UBYTE
    LET bits = number of bits in value n-1
    DO
        LET result = RND MOD (1<<(bits-1))
    LOOP UNTIL (result <= n-1)
    RETURN result
end function

The reason I suggest this behavior to be generated internally by the compiler, instead of provided as a library, is as follows: If n is a constant, then the compiler will know the number of bits and replace it directly above. Otherwise, if n is not constant, then it should generate a simple routine to find out this value.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 3 Guest(s)