Question:
Random number generator - Non-recurring 52 numbers?
kyojustorm
2008-08-17 08:52:39 UTC
One last help!

#include
#include
#include
using namespace std;

int random_integer;

int main()
{
srand((unsigned)time(0));
for(int index=0; index<20; index++)
{random_integer = (rand()%51)+1;

cout << random_integer << endl;}

system ("pause");
}

Thanks for the people that helped me in my previous
questions! I however, need a slight change in this code!
Can it be changed so that it'll generate 52 random, and
non-recurring numbers? That means that it does not
generate 2 same numbers.

Thanks for helping!
Three answers:
richarduie
2008-08-17 10:20:52 UTC
Been WAY too long since I wrote in C/C++. Here's a JavaScript version from which you should be able to abstract the needed steps.

















2016-09-30 06:41:21 UTC
define an array of sixteen components with the numbers a million to sixteen. In a for loop of 8 circumstances get a random style between 0 to fifteen // array subscript do on an analogous time as (array[rnd]=0) get a random style between 0 to fifteen // array subscript end do Print array[rnd] array[rnd]=0 end for for i 0 to 0 print array[i] end-if end for in case you're making the 1st loop do each and all the artwork and don't use the 2d loop then this methodology would be particularly sluggish getting the previous few numbers. via having the 2d loop this methodology would be very speedy. you may play approximately with the style of circumstances around the 1st loop. have exciting.
Johnny W
2008-08-17 08:58:15 UTC
just have an array of numbers that you already used. So every time you generate a number, check it against the list, if it already there, get another one.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...