## Add values to table avr

3 posts / 0 new
Author
Message

How can I randomize a number from the values below and then add that (and/or substitute) to the table. so now I've got a table1 with value \$71, I would like to get a random number from first set and replace it with the current value in table1, and same thing for table2 (apart from use set2) please.

Thank You

Set1: \$3F, \$06, \$5B, \$4F, \$66, \$6D, \$7D, \$07, \$7F, \$67, \$77, \$7C, \$39, \$5E, \$79, \$71

Set2: \$BF, \$86, \$DB, \$CF, \$E6, \$ED, \$FD, \$87, \$FF, \$E7, \$F7, \$FC, \$B9, \$DE, \$F9, \$F1

```table1:  .DB \$71 ;left
table2:  .DB \$F7 ;right```

Last Edited: Sun. Mar 8, 2015 - 10:19 PM

So is your question simply "how do I generate random numbers in assembler"?

The general technique in micros is called  a psuedo random number generator (PRNG) and a Google for "PRNG" will tell you all about it. It's a mathematical algorithm that generates a sequence of numbers in a seemingly random order yet it is fully deterministic and the numbers you get depend solely on where in the sequence you start - known as the "seed". C programs suffer from the same. C has library functions such as rand() that operate a PRNG but it always generates the same sequence of numbers though you can also call srand() to seed it to a new place in the sequence. If you want truly random numbers you need to introduce something called "entropy". This is something like "a varying unknown value". You can maybe get it from the time it takes the user to press a button since power on or something like that as it'll never (if measured in micro or even milli seconds) be exactly the same. Some circuits use a "noisy diode" to introduce entropy. But while you could always use such an entropic number as the random number itself the chance are you still employ a PRNg and just use the entropy to seed it.