Hello,

I am currently trying to find a solution for random number, my program will randomize a list of guys that have to do certain task.

We are 6 people, so the solution i thought was:

rand_person = TPM1CNT % 6 so the output will give me 0,1,2,3,4,5. But it isn´t working as espected.

also the TPM1MOD = 655; so it interrupts every 10 ms

So i will be pleased if someone could tell me the best way to generate a random number.

regards

Hello,

You did not say in what manner the result was not as expected.

Your method requires that the samples occur at a random times, relative to each other, and to the MCU start up, otherwise the result will not be random. Since there are 656 states (0-655) for TPM1, this is not evenly divisible by 6. So the result will be slightly skewed to the results 0 and 1

I would expect that the sample would need to be externally triggered by some means.

Here are a couple of earlier threads about random number generation methods.

https://community.freescale.com/message/24955#24955

https://community.freescale.com/message/45987#45987

Regards,

Mac