All pastes #1648592 Raw Edit

GRNG

public cpp v1 · immutable
#1648592 ·published 2009-10-30 00:01 UTC
rendered paste body
#include <cstdlib>#include <iostream>#include <cmath>#include <ctime>#include <windows.h>/* Generic Random Number Generator v0.8.6.54GRNG is designed to generate sets of random numbers as requested, and output them onto the window in which it is run. It supports checking for repeats and storing the random numbers into variables.Functions:StoreRandom(); - Stores the current value of 'random' into a variable. Can only be done up to 10 variables, after 10 it resets to the 1st and overwrites.Random('x'); - Generates a random number from 1 and 'x'. Ex: Random(10); generates a number from 1 to 10.RepeatCheck(); - Checks the 10 variables for any matches.GenerateSet('a', 'b'); - Generates 'a' numbers 'b' times. Ex: GenerateSet(1, 1) generates 1 number 1 time. Pause(); - Pauses the program until a key is pressed.Bugs:StoreRandom(); - Only supports 10 values.RepeatCheck(); - Only supports 10 values.GenerateSet('a', 'b'); - Maximum supported value of 'a' is 10. */using namespace std; // Declare namespace.int random; // Declare random.int Check,Check1,Check2,Check3,Check4,Check5,Check6,Check7,Check8,Check9,Check10; // Declare check variables.//int z,y; // Set Generation variables.int Random(int x){    random = rand() % x + 1; // Generate a random number from 1 to x.}int StoreRandom() // Efficient way to store variables.{     if (Check == 0)      {     Check1 = random;     Check++;     }     else     {         if (Check == 1)          {         Check2 = random;         Check++;         }         else         {            if (Check == 2)             {            Check3 = random;            Check++;            }            else            {               if (Check == 3)                {               Check4 = random;               Check++;               }               else               {                  if (Check == 4)                   {                  Check5 = random;                  Check++;                  }                  else                  {                     if (Check == 5)                      {                     Check6 = random;                     Check++;                     }                     else                     {                        if (Check == 6)                         {                        Check7 = random;                        Check++;                        }                        else                        {                           if (Check == 7)                            {                           Check8 = random;                           Check++;                           }                           else                           {                              if (Check == 8)                               {                              Check9 = random;                              Check++;                              }                              else                              {                                 if (Check == 9)                                  {                                 Check10 = random;                                 Check++;                                 }                                 else                                 {                                 }                              }                           }                        }                     }                  }               }            }         }     }    }int RepeatCheck() // Check variables against each other.{       for (;random == (Check1||Check2||Check3||Check4||Check5||Check6||Check7||Check8||Check9||Check10);)       {          Random(300); // Regenerate the number.       }}int Pause(){             system("PAUSE>NUL"); // Pause until someone presses a key. Used instead of cin.get(); so we wouldn't need an "Enter" command.}int DisplayNumbers() // If the variable is filled, display it with a space.{    if (Check1 > 0) { cout << Check1 << " "; } else {}    if (Check2 > 0) { cout << Check2 << " "; } else {}    if (Check3 > 0) { cout << Check3 << " "; } else {}    if (Check4 > 0) { cout << Check4 << " "; } else {}    if (Check5 > 0) { cout << Check5 << " "; } else {}    if (Check6 > 0) { cout << Check6 << " "; } else {}    if (Check7 > 0) { cout << Check7 << " "; } else {}    if (Check8 > 0) { cout << Check8 << " "; } else {}    if (Check9 > 0) { cout << Check9 << " "; } else {}    if (Check10 > 0) { cout << Check10 << " "; } else {}     cout << endl;}int GenerateSet(int z, int y){        if (z > 10) { z = 10; } else {} // Save cycles by capping to 10.        srand(time(0)); // Seed random.        for (int j = 0; j < y; ++j) // Loop y times.        {        Check = 0;        for (int i = 0; i < z; ++i) // Loop z times.        {                Random(300); // Generate a number from 1 to 300.                RepeatCheck(); // Check for repeats.                StoreRandom(); // Store random variables efficiently.        }         DisplayNumbers(); // Display all numbers.        }}int main(int argc, char *argv[]){        GenerateSet(10,1);        //cin >> z;        //cin >> y;        cout << "Generic Random Number Generator v0.8.6.54" << endl << "Created by George Kushnir.";        Pause(); // Pause until any key is pressed.        return 0; // Successful execution!}