random number guessage problems

Started by
2 comments, last by ErUs 17 years, 8 months ago
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?
-www.freewebs.com/tm1rbrt -> check out my gameboy emulator ( worklog updated regularly )
Advertisement
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.
ah thankyou, i think i get it :)
-www.freewebs.com/tm1rbrt -> check out my gameboy emulator ( worklog updated regularly )
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.
[edit] fixed a silly counting problem :)
-www.freewebs.com/tm1rbrt -> check out my gameboy emulator ( worklog updated regularly )

This topic is closed to new replies.

Advertisement