Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 06:01 26 Apr 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : MM2 random number on startup

Author Message
GoodToGo!

Senior Member

Joined: 23/04/2017
Location: Australia
Posts: 188
Posted: 11:04pm 02 Apr 2020
Copy link to clipboard 
Print this post

Howdy all,
I hope you are all well in these trying times.
I have multiple LED lighting modules powered by E28's that are designed to flash 3-wire Xmas lights. As a part of the Basic routine, there are multiple sub-routines with the flashing sequences. Upon startup I seed the Random generator with the Timer and then use it to select 1 of the 5 routines as a starting point. Reason being I don't want all the modules to start at the same routine. Great in theory, doesn't work in practice due to all modules seeding the same timer time of course.
I was thinking of maybe using a 'programming resistor' and measure the analog input voltage and use that as a seed? Different resistors should give different voltages, meaning different seed values meaning different random numbers meaning different starting points....
Can anyone else think of a way to generate differing random numbers on module start?

Cheers,

GTG!  
...... Don't worry mate, it'll be GoodToGo!
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 899
Posted: 12:08am 03 Apr 2020
Copy link to clipboard 
Print this post

GtG, could you use the onboard clock to supply current uS value to start as your seed?

OA47
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1664
Posted: 02:06am 03 Apr 2020
Copy link to clipboard 
Print this post

How many E28 Modules?, And I'm Guessing they don't talk to each other.

Just boot & then run one of the 5 sequences & then switch to an alternate random one after a random time?
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1593
Posted: 06:11am 03 Apr 2020
Copy link to clipboard 
Print this post

Could you have a 'start' button for each that you must press to start the sequence? That would add randomness to the startup.

CaptainBoing has discussed random number generation using a noise generator on the Fruit of the shed, see here and here. You can find more circuits on the web.

Bill
Keep safe. Live long and prosper.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5900
Posted: 06:50am 03 Apr 2020
Copy link to clipboard 
Print this post

> AUTOSAVE
spare = 23 ' any spare analog pin left floating.
setpin spare, ain

RANDOMIZE pin(spare)*1000

print rnd()
Saved 53 bytes

> RUN
0.300794
> RUN
0.0807553
> RUN
0.830729
> RUN
0.62072
> RUN
0.270705
> RUN
0.170715
> RUN
0.370797
>



Jim
VK7JH
MMedit   MMBasic Help
 
GoodToGo!

Senior Member

Joined: 23/04/2017
Location: Australia
Posts: 188
Posted: 07:43am 03 Apr 2020
Copy link to clipboard 
Print this post

  Quote  GtG, could you use the onboard clock to supply current uS value to start as your seed?


I originally did, using RANDOMIZE(TIMER). But because all the E28's are connected to the same time switch, they all appeared to use the same TIMER value.

  Quote  How many E28 Modules?, And I'm Guessing they don't talk to each other.

Just boot & then run one of the 5 sequences & then switch to an alternate random one after a random time?


5 so far, they are all independent except for their power source which is switched on by a 230VAC timer. They all run through the sequences in turn, and then repeat.

  Quote  > AUTOSAVE
spare = 23 ' any spare analog pin left floating.
setpin spare, ain

RANDOMIZE pin(spare)*1000

print rnd()
Saved 53 bytes

> RUN
0.300794
> RUN
0.0807553
> RUN
0.830729
> RUN
0.62072
> RUN
0.270705
> RUN
0.170715
> RUN
0.370797
>


Jim, that's perfect! I did try using a high-ish value resistor between pin 7 and the 3.3v supply, which worked, but I also found it worked with the resistor removed! Much better than seeding from the TIMER value in my case.

Thanks for all your help everyone!

Cheers,

GTG!
...... Don't worry mate, it'll be GoodToGo!
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024