Making a randomizer

Hey does anyone know if there is a library code or has the code for what i want to do?

so i want to have a red light and a green light, attached to a shake sensor. When you activate the sensor i want one light to randomly turn on!

You mean the function random() ?

Don't forget to use randomSeed() before if you don't want the same random sequence every time. :wink:

(deleted)

spycatcher2k:
Or see if the millis timer is odd or even!

Bit 2 of micros()?

Maybe your shake sensor has bouncing output? But yea odd/even micros value pretty random.

i love spycatchers answer. here is a code example

// is even
if(millis()%2==0){

taterking:
i love spycatchers answer. here is a code example

// is even

if(millis()%2==0){

The modulo operator is an awfully expensive way (in terms of processor cycles) to determine if an integer is odd or even. Also, as mentioned, I'm thinking micros() would have more "randomness". Since micros() resolution (on an Uno) is 4 us:

if (micros() & 0b100 == 0) {