Non-repeating random number generator

后端 未结 7 1778
清酒与你
清酒与你 2020-12-21 00:57

I\'d like to make a number generator that does not repeat the number it has given out already (C++).

All I know is:

int randomgenerator(){
  int ran         


        
7条回答
  •  生来不讨喜
    2020-12-21 01:34

    //non repeating random number generator
    for (int derepeater = 0; derepeater < arraySize; derepeater++)
    {
        for (int j = 0; j < arraySize; j++)
        {
            for (int i = arraySize; i > 0; i--)
            {
                if (Compare[j] == Compare[i] && j != i)
                {
                    Compare[j] = rand() % upperlimit + 1;
                }
            }
        }
    }
    

提交回复
热议问题