Random Number with Weight

Hey Guys / Girls

I recently got a little Arduino which uses a c++ platform.

What im trying to do is make a little applet that will on button press light a random LED.

NOW what i want is that the random number (1-10) has different probabilities
E.G. 10 has a 5% chance, 6-9 a 35% and 1-5 a 50% chance.

the basic code I have for just pure button press = random led is
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const int buttonPin = 2;                 // the number of the pushbutton pin
const int pause = 1000;                  // Set Delay time

// variables will change:
int buttonState = 0;                     // Variable for reading the pushbutton status
int ledPin = random(10);                 // Sets a Random LED as active

void setup() {
  pinMode(ledPin, OUTPUT);               // Initialize the LED pin as an output:
  pinMode(buttonPin, INPUT);             // Initialize the pushbutton pin as an input:
}

void loop(){
  buttonState = digitalRead(buttonPin);  // read the state of the pushbutton value:
  if (buttonState == HIGH) {             // check if the pushbutton is pressed.if it is, the buttonState is HIGH:
    digitalWrite(ledPin, HIGH);          // turn LED on:    
  } 
  else {
    digitalWrite(ledPin, LOW);           // turn LED off:
  }
}


I asked in the Arduino forums but thought I would ask here too encase ^^

Thanks in advance for any assist.
Couldn't you just use a switch or if else nesting?
Topic archived. No new replies allowed.