3x3 Random Dice Help

I've been working on a 3x3 led matrix that displays a random digit 1-6 at the push of a button. The purpose is to mimic a dice. While individualy addressing the LEDs would be easier, I wanted to make them into a 3x3 LED matrix instead. While my code looks as though it should work, I am too inexperienced to find out why it is not. I have determined that my wiring and components are good.

My code is as follows:

const int r1 = 2;  //Rows 1-3
const int r2 = 3;
const int r3 = 4;

const int c1 = 5;  //Colloms 1-3
const int c2 = 6;
const int c3 = 7;

const int b1 = 8;  //The Button
int b1State = 0;  //The Button's State, not a constant (const) intiger (int) because it changes

int rNumber = 2;  //Holds the value of a randomly generated number;
int dValue = 0;  //Holds the value

int wait = 5;

void setup() {  //Required, only runs once in an Arduino during startup

  pinMode(r1, OUTPUT);  //Sets the pins as outputs
  pinMode(r2, OUTPUT);
  pinMode(r3, OUTPUT);
  pinMode(r3, OUTPUT);
  pinMode(c1, OUTPUT);
  pinMode(c2, OUTPUT);
  pinMode(c3, OUTPUT);

  pinMode(b1, INPUT);  //Sets the button pin to input

  randomSeed(analogRead(0));  //Begins the generation of random numbers
}  //Closes off void setup()

void loop() {  //As its name implies, this section loops forever
  //Ties the physical button pin to the intiger value, changing it when the button is pressed
  b1State = digitalRead(b1);

  if (b1State == HIGH) {  //Checks if the button is pressed, then does something
    rNumber = random(0, 5);  //Generates a random number 0 - 5 and sets rNumber to that number
    delay(1000);  //Stops the program for 1000 milliSeconds, or 1 Second
  }
  //Displays number 1
  while (rNumber == 0) {  //During the time that rNumber is exactly equal to 0, the display will continue to loop these commands
    digitalWrite(r1, LOW);  //Sets the row to low shutting voltage off
    digitalWrite(r2, HIGH);  //Sets row 2 to high applying voltage to the led
    digitalWrite(r3, LOW);
    digitalWrite(c1, HIGH);  
    digitalWrite(c2, LOW);  //Sets the collumb to low, allowing voltage to travel though it
    digitalWrite(c3, HIGH);
  }
  //Displays number 2
  while (rNumber == 1) {
    if (dValue == 0) {         //Because 2 LEDs must be lit, each must be individualy addressed
      digitalWrite(r1, HIGH);  //An if statement inside a while statement does nicely
      digitalWrite(r2, LOW);   //Using the principle of Persistance of Vision (POV)
      digitalWrite(r3, LOW);   //The LEDs appear to be lit even when they are not because
      digitalWrite(c1, HIGH);  //They are being switched on and off too quickly to be seen
      digitalWrite(c2, HIGH);
      digitalWrite(c3, LOW);
      delay(wait);
      dValue++;  //Increses dValue by one, making the previous statement false in the next loop
    }
    else {
      digitalWrite(r1, LOW);
      digitalWrite(r2, LOW);
      digitalWrite(r3, HIGH);  //Sets the row to high, applying voltage to it
      digitalWrite(c1, HIGH);  //Sets the collumb to high, stopping the flow of electricity by
      digitalWrite(c2, HIGH);  //Applying the same ammount of voltage on either side of the LED
      digitalWrite(c3, LOW);   //And shutting the LED off
      delay(wait);
      dValue = 0;  //Sets the dValue to 0 for the next loop
    }
  }
  //Displays number 3
  while (rNumber == 2) {
    if (dValue == 0) {
      digitalWrite(r1, HIGH);
      digitalWrite(r2, LOW);
      digitalWrite(r3, LOW);
      digitalWrite(c1, LOW);
      digitalWrite(c2, HIGH);
      digitalWrite(c3, HIGH);
      delay(wait);
      dValue++;
    } 
    if (dValue == 1) 
    {  //An addational if statement is needed to complete the liting of the third LED
      digitalWrite(r1, LOW);
      digitalWrite(r2, HIGH);
      digitalWrite(r3, LOW);
      digitalWrite(c1, HIGH);
      digitalWrite(c2, LOW);
      digitalWrite(c3, HIGH);
      delay(wait);
      dValue++;
    }
    else {
      digitalWrite(r1, LOW);
      digitalWrite(r2, LOW);
      digitalWrite(r3, HIGH);
      digitalWrite(c1, HIGH);
      digitalWrite(c2, HIGH);
      digitalWrite(c3, LOW);
      delay(wait);
      dValue = 0;
    }
  }
  //Displays number 4
  while (rNumber == 3) {
    if (dValue == 0) {
      digitalWrite(r1, HIGH);
      digitalWrite(r2, LOW);
      digitalWrite(r3, LOW);
      digitalWrite(c1, LOW);
      digitalWrite(c2, HIGH);
      digitalWrite(c3, HIGH);
      delay(wait);
      dValue++;
    }
    if (dValue == 1) {
      digitalWrite(r1, HIGH);
      digitalWrite(r2, LOW);
      digitalWrite(r3, LOW);
      digitalWrite(c1, LOW);
      digitalWrite(c2, LOW);
      digitalWrite(c3, HIGH);
      delay(wait);
      dValue++;
    }
    if (dValue == 2)  {
      digitalWrite(r1, HIGH);
      digitalWrite(r2, LOW);
      digitalWrite(r3, LOW);
      digitalWrite(c1, LOW);
      digitalWrite(c2, HIGH);
      digitalWrite(c3, HIGH);
      delay(wait);
      dValue++;  //Another addational step is needed to display the fourth LED
    }
    else {
      digitalWrite(r1, LOW);
      digitalWrite(r2, LOW);
      digitalWrite(r3, HIGH);
      digitalWrite(c1, HIGH);
      digitalWrite(c2, HIGH);
      digitalWrite(c3, LOW);
      delay(wait);
      dValue = 0;
    }
  }
  //Displays number 5
  while (rNumber == 4) {
    if (dValue == 0) {
      digitalWrite(r1, HIGH);
      digitalWrite(r2, LOW);
      digitalWrite(r3, LOW);
      digitalWrite(c1, LOW);
      digitalWrite(c2, HIGH);
      digitalWrite(c3, HIGH);
      delay(wait);
      dValue++;
    }
    if (dValue == 1) {
      digitalWrite(r1, HIGH);
      digitalWrite(r2, LOW);
      digitalWrite(r3, LOW);
      digitalWrite(c1, HIGH);
      digitalWrite(c2, HIGH);
      digitalWrite(c3, LOW);
      delay(wait);
      dValue++;
    }
    if (dValue == 2) {
      digitalWrite(r1, LOW);
      digitalWrite(r2, HIGH);
      digitalWrite(r3, LOW);
      digitalWrite(c1, HIGH);
      digitalWrite(c2, LOW);
      digitalWrite(c3, HIGH);
      delay(wait);
      dValue++;
    }
    if (dValue == 3) {
      digitalWrite(r1, LOW);
      digitalWrite(r2, LOW);
      digitalWrite(r3, HIGH);
      digitalWrite(c1, LOW);
      digitalWrite(c2, HIGH);
      digitalWrite(c3, HIGH);
      delay(wait);
      dValue++;
    }
    else {
      digitalWrite(r1, LOW);
      digitalWrite(r2, LOW);
      digitalWrite(r3, HIGH);
      digitalWrite(c1, HIGH);
      digitalWrite(c2, HIGH);
      digitalWrite(c3, LOW);
      delay(wait);
      dValue = 0;
    }
  }
//Displays number 6
  while(rNumber == 5) {
    if (dValue == 0) {
      digitalWrite(r1, HIGH);
      digitalWrite(r2, LOW);
      digitalWrite(r3, LOW);
      digitalWrite(c1, LOW);
      digitalWrite(c2, HIGH);
      digitalWrite(c3, HIGH);
      delay(wait);
      dValue++;
    }
    if (dValue == 1) {
      digitalWrite(r1, HIGH);
      digitalWrite(r2, LOW);
      digitalWrite(r3, LOW);
      digitalWrite(c1, HIGH);
      digitalWrite(c2, HIGH);
      digitalWrite(c3, LOW);
      delay(wait);
      dValue++;
    }
    if (dValue == 2) {
      digitalWrite(r1, LOW);
      digitalWrite(r2, HIGH);
      digitalWrite(r3, LOW);
      digitalWrite(c1, LOW);
      digitalWrite(c2, HIGH);
      digitalWrite(c3, HIGH);
      delay(wait);
      dValue++;
    }  
    if (dValue == 3) {
      digitalWrite(r1, LOW);
      digitalWrite(r2, HIGH);
      digitalWrite(r3, LOW);
      digitalWrite(c1, HIGH);
      digitalWrite(c2, LOW);
      digitalWrite(c3, HIGH);
      delay(wait);
      dValue++;
    }
    if (dValue == 4) {
      digitalWrite(r1, LOW);
      digitalWrite(r2, LOW);
      digitalWrite(r3, HIGH);
      digitalWrite(c1, LOW);
      digitalWrite(c2, HIGH);
      digitalWrite(c3, HIGH);
      delay(wait);
      dValue++;
    }
    else {
      digitalWrite(r1, LOW);
      digitalWrite(r2, LOW);
      digitalWrite(r3, HIGH);
      digitalWrite(c1, HIGH);
      digitalWrite(c2, HIGH);
      digitalWrite(c3, LOW);
      delay(wait);
      dValue = 0;
    }
  }
}  //Ends void loop, and returns the program to its beginning

Any help is much appreciated. Cheers!

First off, you didn't explain exactly what isn't working.

It seems unlikely, though, that you want to use a while loop:

  while (rNumber == 0) {  //During the time that rNumber is exactly equal to 0, the display will continue to loop these commands
    digitalWrite(r1, LOW);  //Sets the row to low shutting voltage off
    digitalWrite(r2, HIGH);  //Sets row 2 to high applying voltage to the led
    digitalWrite(r3, LOW);
    digitalWrite(c1, HIGH);  
    digitalWrite(c2, LOW);  //Sets the collumb to low, allowing voltage to travel though it
    digitalWrite(c3, HIGH);
  }

There is nothing in the body of the while loop that changes the value in rNumber, so, once the while loop starts, it never ends.

Yes, that is probably my problem. Is there any way to remedy that? How can I make the program check if the button is pressed, should I insert some if statements into the while loops?

Is there any way to remedy that?

Yes write code to do it.

Basically you want only one routine that multiplexes a display according to some values in an array. Then you simply change the numbers in the array to change what is displayed. So refresh once, then look at input switches, then refresh again and so on.