random number 0 or 1 or 2 (18m2)

motters

New Member
hi everyone,
i have been having a bit of a bad time with pic at the moment. Burning out two 18m2 because of a faulty power supply and pic not programming. But i have sorted them problems out now. (power supply in the bin lol :p)
but i have 1 last problem that i can not fix.

i have been tring to genarate a random number (0 or 1 or 2) and save that random number in a varable using picaxe and logicator.
then that varable will deside what led to turn on.I HAVE DONE THIS PART

now i have been back after school (had to buy my own 18m2 :( lol) every day for the past 4 weeks(2:30-5) and spending hours at home. now i do code php at a high level currently doing a booking system for a department in manchster uni so i do have a good idea on coding. though basic is quite new to me.

What i have tried
1)
i have tryed the random command that genarates a number from 0-255. Now i have tried bitshifting (dividing by 128) it worked on the software, but when programed onto the pic it went to the same led MOST time it just was not random at all.

2)
so i scarpped that idea and then i tried using the random command and saving that command to a varable and then running that varable though some compare eg (k the varable i saved the random number to)
k >= 84 (if yes then i set the varable m to 0)
k >= 169 (if yes then i set the varable m to 1)
k >= 170 (if yes then i set the varable m to 2)
(this to pick which led to turn on).
Again on the software this worked fine. On the pic i get led 1 lighting first then led 2 lighting ALL the time

so the only option i have now is to do some kind of look up table. Though this is not so random

so that is what i have tried. Please can some one give me some help or a way to genatare a random number (0 or 1 or 2)

thanks you so much. i really need this. and i have been working my hardest but just not getting there.
p.s
i have been reading about that random command and some one said you need to seed the time function to the random command. i dont know what this means.
so can some one exsplain how to use the randoms command properly.
At the moment i have just put the random number on to the flowchart and set it to put the value into varable k

thanks alot for your time
UPATE
i have just slightly improved it
am am now making just the random command k three time eg
random k ----------random k----------------random k--------------them a load od compares

but still it light up mainlly the same two leds
 
Last edited:

Technical

Technical Support
Staff member
Post your .plf logicator file as an attachment and we will take a lot. As e points out the trick is to make sure random is always within a loop, being called multiple times whilst waiting.
 

motters

New Member
THANKS

ok thanks
should i post my whole flowcart or just the bit that create the random number.
my whole flow chart is quite big (dance mat game)
 

hippy

Ex-Staff (retired)
The whole flowchart (.plf file) would be best then we can see what you are doing and there hopefully won't be any misunderstandings or confusion.
 

motters

New Member
THANKS

ok thanks everyone i was just about to upload and suddenly i fix it!!!!:D
i forgot that the 18m2 can run parrell tasks so i put the random command in another task / start in a loop and pull a value from that for ever changing value when needed.

THANKS EVERY ONE YOU SAVED MY LIFE SERIOUSLY :D:D:D
 

hippy

Ex-Staff (retired)
That's a brilliant solution for the 18M2, so well worked out. In other PICAXE you have to meld the multiple random statements within actual loops of the PICAXE code which can be more difficult.
 
Top