# random number guessage problems

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

## Recommended Posts

here is the problem. I am making a (single digit) random number Guesser, it tries to guess the next number based on the preveous numbers and how many numbers have been entered since the start of the session. random numbers are entered one after the other, like 93659163. (when training) I store all the numbers in a format like this: typedef struct { char thenumber; //number entered int freq; //times this pattern has happened before int history; //count of guesses in the session before this arose char lastno; // the number before this char lastno2; // the number before that above char lastno3; // the number before that above } numentry; I need to devise a scoring system for the most likly next number based on a database of previous examples. at first i thought points = (for each matching param +=5) (+frequency), but a numentry with a high frequency will win even if it is totaly unrelated to the previous numbers. DO you have any suggestions?

##### Share on other sites
This is basicly the same thing order n data compressors do. If you're not worried about speed, or you know there won't be a long list of numbers, an idea is:

create an array to hold all the numbers in the order they are added, we'll call it "num_list"

create an array to hold the temporary frequencies of numbers, we'll call it "freq"

when you want to find out the probability of a number, look at the last X numbers in num_list. Find out where those last numbers are seen elsewhere in num_list, when the numbers are found check what number comes after those and increment it in freq.

Sort freq so the number that occurs the most is the one you'll guess is the correct number.

(hope that wasn't too confusing)

edit: you might want to keep the amount of numbers you're searching for small until the list gets bigger, since in a small list it will probably be harder and less accurate to find long patterns that occur once or not at all.

##### Share on other sites
ah thankyou, i think i get it :)

##### Share on other sites
HERE is a version that works fairly well for me. After about 200 entries it gets %20 of my random numbers and it get 35-40% when spazzing out on the number keys.
 fixed a silly counting problem :)

1. 1
Rutin
42
2. 2
3. 3
4. 4
5. 5

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

• Total Topics
633378
• Total Posts
3011566
• ### Who's Online (See full list)

There are no registered users currently online

×