• Advertisement


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

Generating random Oblio number

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

If you intended to correct an error in the post then please contact us.

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 this post

Link to post
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 number


// main loop

for(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.


Final Frontier Trader

  • Advertisement