# trying to randomly turn on 3 lights based on a randomly assigned var value

it doesnt turn on any lights it just stays off any help appriciated basicly i am trying to make a 3 light roulette game red green and yellow lights

int p;
void setup() {
// put your setup code here, to run once:
p=random(1,100);
if (p>1)
{
if (p<49)
{
digitalWrite(13,HIGH);
}
else{goto green;}
}
green:
if(p>49)
{
if(p<51)
{
digitalWrite(12,HIGH);
}
else{goto red;}

}
red:
if(p>51)
{
digitalWrite(11,HIGH);

}
}

void loop() {
// put your main code here, to run repeatedly:

}

Pins default as inputs, so you need to pinMode(pinnum, OUTPUT); for a start. Then rethink all that goto stuff.

You have no action for p = 0, p = 49 and for p = 51.

Use(p>=51)
When you want to have two things to be true for something to happen:if (p>=0 && p<49) {digitalWrite(13,HIGH);}
Get rid of the goto. They are only forking the program to the next line…

Jacques

First, welcome to the Forum and good job on using code tags to make your first post! Most beginners here don’t read the notes at the top of the Forum.

If you want, you can use Ctrl-T on your source code while it’s in the IDE’s source window to format it into a common C style before posting. It makes it easier for us to read.

1. the 'setup' function is for initializing your pins

2. if you want three options, why would you pick a random number from 100? why not 3?

3. if you use the 'loop' function, you could repeat the 'spin of the wheel' every 'x' seconds or so

4. you could also introduce a few more numbers by using combinations 4=green+yellow, etc. etc.

if (p > 1)
{
if (p < 49)
{
digitalWrite(13, HIGH);
}
else
{
goto green;
}
}
green:

You have no need to use goto here (or anywhere) because if the test fails to return true then the program will carry on to the next statement. Try this

if (p > 1)
{
if (p < 49)
{
digitalWrite(13, HIGH);
}
}
//carry on with the code here

bitflogger:
2) if you want three options, why would you pick a random number from 100? why not 3?

Standard roulette requires probability ratios 1:18:18 or 1:9:9 depending on which continent you
are on, so I guess the 3 options have differing probabilities.

You also have a problem in that you have code to write HIGH to those pins, but you don't have any code to write them back to LOW. So once your LEDs come on they will stay on until you reset the program.