Home Products Services Articles Training ZS1GL Contact

/*Program to generate 6 weighted random numbers
 * which limit possibilty of having to share winnings with 
 * the mob
 * There are 2 sections, first one picks and prints a random
 * number out of the array which has skipped "date" values 
 * between 1 and 31 by shuffeling the array and then 
 * selecting the first 4 values
 * The next loop does the same but uses 1-31 
 * We weight the selection by using 4 from the first selection 
 * and 2 from the second
 * So, first 4 are between 32 and 52 and last 2 are 1-31
 */
//leave out possible calendar dates:
byte numArray[] = {32,33,34,35,36,37,38,39,40,41,42,43,
                   44,45,46,47,48,49,50,51,52};
const byte  n = sizeof(numArray) / sizeof(numArray[0]);

//include calendar dates:
byte numArray_2[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
          16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31};
const byte  m = sizeof(numArray_2) / sizeof(numArray_2[0]);

///////////////////////////////////////////////
void setup()
{
  randomSeed(analogRead(3));
  Serial.begin(9600);
  for (byte loops=0;loops<=6;loops++) //make 7 sets for A to H panels
    {
      //first four numbers:
      for (byte i = 0; i < n; i++) 
      {
      byte j = random(i, n);
      // swap numArray[i] and numArray[j]
      byte temp = numArray[i];
      numArray[i] = numArray[j];
      numArray[j] = temp;
    }
    
    for (byte count = 0;count<= 3; count++)
        {
          Serial.print(numArray[count]);
          Serial.print(" ");
        }
    
     //----------------------------------------------
     //last 2 numbers:
     for (int i = 0; i < m; i++) 
     {
      byte j = random(i, m);
      // swap numArray[i] and numArray[j]
      byte temp = numArray_2[i];
      numArray_2[i] = numArray_2[j];
      numArray_2[j] = temp;
    }
    
    for (byte count = 0;count<= 1; count++)
        {
          Serial.print(numArray_2[count]);
          Serial.print(" ");
        }
    
      Serial.println();
    }
}
////////////////////////////////////////////////
void loop() 
{ 

}
////////////////////////////////////////////

php logo mysql logo   arduino logo