Generating random Oblio number

Started by
0 comments, last by MrPoopypants 21 years, 4 months ago
Hello I am writing a very simple Oblio game in C++. The goal of the game is to guess a four digit number where no two integers are the same (for example: 1583 or 1372). The user will input his or her guess and will in return recieve an ordered pair ( x , y ). ''x'' Tells the user how many integers are in the correct spot, and ''y'' tells the user how many integers are in the oblio number but are not in the right spot. So if one recieves (4,0) then or she has won. What I do not understand, however, is how I would write a function to generate a random oblio number and create the ordered pair... If anyone could help me I''d really appreciate it Thanks!
(0110101101000110)The Murphy Philosophy: Smile . . . tomorrow will be worse.
Advertisement
Just posting fast between working on the fft engine, but here''s a fast and easy idea.

Create an array of four integers, randomize each number, then check if they match any previous, if then randomize again.

Here''s some code.


  int oblio[4];    // holding the random numbersrand(time());// main loopfor(int i = 0; i < 4; i++){    oblio[i] = rand() % 9;    // sub-loop    for(int y = i; y >= 0; y--)    {        if(oblio[i] == oblio[y])        {            oblio[i] = rand() % 9;            y = i;        }    }}  


That should do it. I''m not sure if the code works perfectly, but you should get the idea.

Cheerios!

-----------------------------
Final Frontier Trader
-----------------------------Final Frontier Trader

This topic is closed to new replies.

Advertisement