Robotic hand, rock, paper, scissors

Hi,

I'm coding this robotic hand to play rock, paper, scissors and I'm trying to get the code to be completely random each time.

I've coded the hand movements but I'm stuck on how to randomly select the loop to run.

Is there a way to assign the loops a numerical value and use a random function to select and run a loop?

Any help would be greatly appreciated.

Kwazikwow

Hi,

Start here. http://www.arduino.cc/en/Reference/Random

Tom..... :)

Without seeing your code I have no idea what you mean by loops

If you mean that you have 3 different functions you could do something like this

randomNumber = (whatever you do to get a number)
if (randomNumber == 0) {
   rock();
}
else if (randomNumber == 1) {
   paper();
}
else {
   scissors();
}

...R

TomGeorge: Start here. http://www.arduino.cc/en/Reference/Random

.... perhaps as the trigger for this.

edit: I can't wait to see the arm do Rock, Paper, Scissors, Lizard, Spock

Robin2:

randomNumber = (whatever you do to get a number)

if (randomNumber == 0) {
  rock();
}
else if (randomNumber == 1) {
  paper();
}
else {
  scissors();
}

Unless you’re quite specific with your RNG that’s not going to lead to a well distributed system …
OP, take note of the random seed ‘problem’ in the docs (that is helpful in debug often so it’s not so much a problem) - another way to do it would be pushing a button that sampled ‘millis’ every time you played a game.
But I guess if you’re going to do that you just use millis and % function (scaled and offset appropriately) - i.e build your own RNG.