1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

C++ Rand

Discussion in 'C++' started by siikaisz, Sep 2, 2010.

  1. siikaisz

    siikaisz New Member

    Joined:
    Sep 2, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    I have thoose numbers 1,2,4,8,16,32. I made function
    Code:
    int RandomNumGen(int NumberCount)
    {
    int RandomNumber;
    int SumNumber;
    int NumberSumm=0;
            for(int n=0;n < NumberCount;n++)
            {
                    srand(static_cast(time(NULL)));
                    RandomNumber= (rand()%6+1);
                    switch ( RandomNumber) {
                      case 1 : 
                            SumNumber = 1;
                            break;
                      case 2 : 
                            SumNumber = 2;
                            break;
                      case 3 : 
                            SumNumber = 4;
                            break;
                      case 4 : 
                            SumNumber = 8;
                            break;
                      case 5 : 
                            SumNumber = 16;
                            break;
                      case 6 : 
                            SumNumber = 32;
                            break;
                    }
                    NumberSumm=NumberSumm+SumNumber;
            }
    return NumberSumm;
    }
    but problem is how to make not choose that number what already previously was already?
    Example if i give function number 3

    count=RandomNumGen(3);

    function give me backnumber 35 wich is 32 and 2, and 1 summ - that is ok and correct. But cant be example 36 wich is 32 and 2, and again 2 summ - incorrect. Cant return number what is already generated previously.

    Thanks ;)
     

Share This Page