View Single Post
Old Nov 28th, 2005, 10:48 AM   #21
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Quote:
Originally Posted by groovicus
MODE:
To find the mode, all you need is a simple array (filled with zeroes) that is the same size as the largest possible random number that can be generated . Then you loop through your array of 1000 randomly generated numbers. If the first number is a one, then you put the number one in index one in your counting array. If your second number is a one, then you increment the count at one again, so then you have two. Whatever the random number is, increment the count in your array by one. Once you are done, then go through your counting array, see which cell has the largest number, and that is your mode.
That's hideously inefficient. You just need three integers and one integer array: the current modal numbers (array), the modal number count, the current number and the current number count.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote