Either change the way this works or cause compiler warning
Posted: Sun Mar 10, 2013 8:48 pm
The code below will to most coders be quite confusing, this is because this line actually calls the function myRandom() two times.
My suggestion is either that the compiler is changed so this can not occur or that it gives the user a compiler warning informing that this may cause a unexpected result.
This is previously discussed here:
http://www.purebasic.fr/english/viewtop ... =4&t=34908
Code: Select all
myArray(myRandom(9)) + 1
My suggestion is either that the compiler is changed so this can not occur or that it gives the user a compiler warning informing that this may cause a unexpected result.
This is previously discussed here:
http://www.purebasic.fr/english/viewtop ... =4&t=34908
Code: Select all
EnableExplicit
Procedure myRandom(number)
number = Random(number)
Debug "random number generated = "+Str(number)
ProcedureReturn number
EndProcedure
Define Dim myArray(9), i, x
For i=0 To 9
myArray(i) = i
Next
RandomSeed(0)
x = myRandom(9)
Debug "Expected output: "+Str(myArray(x)+1)
RandomSeed(0) ;give it the same starting point as above
myArray(myRandom(9)) + 1
Debug "Actual output: "+Str(myArray(x))