Random function - How to limit it ??
Hello,
I want to know if it is possible to use the RANDOM function under a limited range.
Let me explain :
I want to use the RANDOM function and the BRANCH to make 39 differents things (branch to 39 differents labels to execute differents functions).
There is the code
RANDOM result
BRANCH result,[state1, state2, state3, state4,...,state39]
This is equivalent to do this
If result=0 go to state1 subroutine
if result=1 go to state2 subroutine
...
The RANDOM function give me 0 to 65535 results, how can I limit it to 0-38 for my 39 states ??
thanks for your help!
Martin
Random is not a real random
Hello,
I've got another question about the Random function.
Is it a real random function that comes with PBP ??
I've write every result of the Random function (with the 0-38 trick listed above) in the internal EEPROM of my PIC16F84A and I found that the result seems to follow a patern.
Here are the results of the random function (in Hex format)
18 0A 15 03 07 0E 1C 11 23 07 0E 1C 11 23 07 0E 1C 11 23 07 0E 1C 11 23 07 0E 1C 11 23 07 0E 1C 11 23 07 0E 1C 11 23 07 0E 1C 11 23 07....
the patern seems to be : 07 0E 1C 11 23 (Hex) or 7 14 28 17 35 in decimal format.
Everything seems to be good on the first results but after some loop the results seems to follow a patern. I also found that every time I reset the chip, it start with the same result : 18, 0A, 15, 03...
Is there a method to get a "real" random ?
thanks