[sdiy] Pseudo randoms in software
David Hughes
dhughes at globalnet.co.uk
Thu Nov 21 12:11:24 CET 2002
Hello Gents,
I've been watching this thread with some insterest because I just ran into the
problem of random numbers with our sequencers.
Computing a random number is fairly easy but can be time consuming for a
microprocessor, especially if you're attempting to calculate a randomised value
in an interrupt service routine and you don't want the timing integrity of the
sequencer to be affected.
My solution was as follows. I wrote a quick noddy program in Javascript to
produce a series of random numbers in the range of 1..255 using the browser's
Random() call. I then cut and pasted the browser output into the CodeVision text
editor and turned the results into a large look up table. (Program memory isn't
in short supply on the Mega1218 chip!)
Ok, so using a lookup table isn't random at all really but you can fake random
behaviour such that the end user won't notice any patterns by updating the
pointer into the lookup table every time an event happens. In our case, an event
can be a timing event or a change on the front panel pots or the turning of a
rotary encoder. Whatever happens, the program reads the table entry at the
current location, adds that to the index and jumps forward to the new index
point, wrapping at the top of the table. You probably don't need to do this last
step but it costs very little programming effort just to make the output a
little less predictable.
The code to do this is minimal, probably around ten lines at most. If anyone
wants to see the code itself, mail me off list.
Meanwhile, I've uploaded a sample of the Atem sequencer playing a random series
of notes to the web pages.
Best wishes
David
-----------------------------------------------------------------------------------
Infection Music
http://www.infectionmusic.co.uk
-----------------------------------------------------------------------------------
More information about the Synth-diy
mailing list