# how do you make random numbers?

Show 80 post(s) from this thread on one page
Page 2 of 2 First 12
• 11-21-2005
Prelude
>I don't understand how shuffling the entire vector twice would
>be conceptually simpler than just picking a random number from 1 to 8.
Conceptually, it's probably easier to see how shuffling a vector results in a suitably random value while shifting the range of a random number with the remainder operator isn't immediately obvious unless you're a math major. On the other hand, the former is less likely to be used if all you need is a quick and dirty roll of the dice.

>I doubt the low vs high order bits issue will have much of an
>impact if you're looking for the easiest method.
Or at all, since these days compiler vendors have figured out that their implementations of rand sucked ass. The low order bits problem isn't as bad as it used to be, but you still have to contend with the distribution problem of shrinking a range that was fragile to begin with.

Prelude's other FAQ. ;)
• 11-21-2005
findme
yawn i got it.
Code:

```//adds the iostream library to the program #include <iostream> #include <cstdlib> #include <stdio.h> #include <stdlib.h> #include <time.h> #define BOOL_H #undef true #undef false //informs the compiler you are using the standard library set using namespace std; const int LOW = 1; const int HIGH = 6; int firstDie; int secondDie; int Choice; int yes; /* Variables to hold random values for the first and the second die on each roll. */ int main ()    {     time_t seconds;   time(&seconds);   srand((unsigned int) seconds);   for ( ;; )   {       cout << "Round 1 \n";       cout << "Would you like to roll this round? [1 for yes, 0 for no]:\n\n";   if ( cin >> yes || yes == 0 )   {}   else       {firstDie = rand() % (HIGH - LOW + 1) + LOW; (secondDie = rand() % (HIGH - LOW) + 1) + LOW; cout << "you rolled a "<< firstDie << " and a " << secondDie << endl; break;}      }       system("pause\n\n\n");   return 0; }```
• 11-21-2005
7stud
Quote:

yawn
Well, well, well. yawn right back at you.

Quote: