random generator

Hey,

I want to make a program that makes a random sequence;In 7 on the 10 cases a led must light up and in 3 out of 10 cases the led must be out. I have tried it on this way;

/*
  


 set pin numbers:
 
*/ 
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  15;      // the number of the LED pin
long randNumber;
const int output = 8;
int led = 13;
const int randompin = 0;

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT); 
Serial.begin(9600);

  // if analog input pin 0 is unconnected, random analog
  // noise will cause the call to randomSeed() to generate
  // different seed numbers each time the sketch runs.
  // randomSeed() will then shuffle the random function.
  randomSeed(analogRead(0));  
  pinMode(led, OUTPUT); 
}

void loop(){
  

  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {     
    // turn LED on:    
    randNumber = random(10);
  Serial.println (randNumber);  
  } 
  else {
    // turn LED off:
    analogWrite(randompin, LOW); 
  }

   

 delay(50);
 
 if (randNumber <= 7) {
   digitalWrite (output, HIGH);
   delay(1000);
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);   
  }
 else {  
   digitalWrite (output, LOW); 
 }
}

But this don't work;the led is always on.
Are there other options to make this kind of program?

Thanks Lowie

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

As soon as I see something like this I think 'array'!

Set up an array containing the output pin numbers, and then when you have selected your random number, turn that pin in the array element high?

You might also want to test your switch input has changed states, not simply is HIGH. Has it gone from LOW to HIGH, if so then process...

  randNumber = random(10);

That will generate 10 different values between zero and 9. So far, so good.

 if (randNumber <= 7) {

This will return true for values between zero and 7. That's 8 of the 10 cases, with only 8 & 9 returning false.