Non-repeating random number generator

后端 未结 7 1777
清酒与你
清酒与你 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;
                }
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题