I place a random statement to the main loop, that way while waiting for a button push you are randomizing in the background.
Paul
I place a random statement to the main loop, that way while waiting for a button push you are randomizing in the background.
Paul
+-------------------------------------------------------------------+
| PBP 2.47/2.50 | MCS+ 3.0.0.5 | U2 Prog | Vista x64 | NO SLEEP!!!!!!! |
+-------------------------------------------------------------------+
Thnx for the replies, as you can see i did have a loop like that right at the beginning of the program
jmp1:
random temp
if sw1 = 1 then goto start
goto jmp1
I first tried using a similar loop between each number fetching routine, but this meant pressing the button 5 times.
In the end i have used 2 pics. The first one uses 5 random vars to pause for random ammounts of micro seconds, and acts as the button press, the second one simply counts up until it sees a button press, then i use //9 to get the number from 0 to 8. checks to see if it is zero or has already been chosen & repeats if so.
In conclusion, the pbp random statement is the least random thing I have ever come across, a mate tells me he had a similar problem with visual basic, so it is not a flaw with PBP. I just wish the lottery used a computer, I might be able to work out the winning numbers.
Thanks for the help guys
Try something like this:
LET X = 0
JMP1:
LET X = (X + 1)
IF X >=9 THEN LET X = 0
IF SW1 = 1 THEN START
GOTO JMP1
YOU WILL GET A RANDOM NUMBER FROM 0 TO 8. IT WILL BE TRULY RANDOM. IT IS POSSIBLE FOR THE NUMBER TO BE THE SAME WITH A SUBSEQUENT PUSH OF THE SWITCH.
Dave
Always wear safety glasses while programming.
What I usually do when I need to use RANDOM, is to seed it with a 16 bit timer value, and then add a few other variables I've got around and always tie grabbing that random number with some sort of human interaction.
If you've got an event that relies on human interaction somehow (i.e. button press) and a tight loop somewhere, there ain't no way you're going to get a continuously repeatable result.
True, RANDOM in PBP isn't all that random, but when you start adding the 'YOU' factor to it, you can get decent results...
Like maybe use a floating pin or some other means for a spare pin to pick up some "static" to generate an interupt or something?. But there again you may only pick up 60Hz (or 50), but i have heard of people doing this to get random randomness
Bookmarks