#### Archived

This topic is now archived and is closed to further replies.

# Generating random Oblio number

This topic is 5827 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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!

##### Share on other sites
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!

-----------------------------

1. 1
Rutin
41
2. 2
3. 3
4. 4
5. 5

• 18
• 20
• 14
• 14
• 9
• ### Forum Statistics

• Total Topics
633368
• Total Posts
3011532
• ### Who's Online (See full list)

There are no registered users currently online

×