🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Need AI Help dealing with trends in Random Numbers

Started by
2 comments, last by AngleWyrm 10 years, 8 months ago

I created some sample code that select 0-9 number randomly, I know in AI it is not possible to predict which number will come next, but can i Identify which number(s) is leading, at one point in time a set of number(s) might be leading then in another period of time another set of number(s) leads. As theories in equilibrium states given enough rolls they will tend to equalize over a period, or time, how can i construct a AI to identify what number(s) are currently leading? So in others words there are (0-9) numbers, if i needed to find out what top 80%, or even the top 60% of numbers are currently leading, how would i go about doing this?

Also keep in mind i am very new to AI, and the sample code only generate random number and pauses every 500 millisecond when a new number is leading. the code is programmed in C# and i used a tool called Snippet Compiler to run, and compile it which can be found here: http://www.sliver.com/dotnet/snippetcompiler/

To run it just download snippet compiler, then select .Net Framework 3.5 then run.


    using System;
    using System.Collections.Generic;

    public class ColumnPick
    {
       static System.Collections.Hashtable m_ht
          = new System.Collections.Hashtable();
       
       //we use enum to create our coin
        public enum Face { Zero =0, One = 1, Two, Three, Four, Five, Six, Seven, Eight, Nine };

       private static string[] m_faces = Enum.GetNames(typeof(Face));
       
        //if you do not define a random variable outside of your functions,
        //you will get the same random number
        private static Random r;
       
       private static Face m_lastface;
       private static Face m_curface;
          
       public static Face toss()
        {
          r = new Random(DateTime.Now.Millisecond);
          
          int value = r.Next(0, 10);
          
            return (Face)Enum.Parse(typeof(Face), m_faces[value]);
        }
       
       public static void RunSnippet()
       {
          Face face;
          
          foreach (string s in m_faces)
          {   face = (Face)Enum.Parse(typeof(Face), s);
             m_ht.Add(face, 0);
          }
          
          int maxIndex = 15000;
          int index = 0;
          
          while (index < maxIndex)
          {
             face = toss();
             
             if (!m_ht.ContainsKey(face))
                m_ht.Add(face, 1);
             else
                m_ht[face] = (int)m_ht[face] + 1;
             
             int zero = (int)m_ht[Face.Zero];
             int one = (int)m_ht[Face.One];
             int two = (int)m_ht[Face.Two];
             int three = (int)m_ht[Face.Three];
             int four = (int)m_ht[Face.Four];
             int five = (int)m_ht[Face.Five];
             int six = (int)m_ht[Face.Six];
             int seven = (int)m_ht[Face.Seven];
             int eight = (int)m_ht[Face.Eight];
             int nine = (int)m_ht[Face.Nine];
             
             if ((zero > one) && (zero > two) && (zero > three) && (zero > four)
                && (zero > five) && (zero > six) && (zero > seven) && (zero > eight)
                && (zero > nine)){
                m_curface = Face.Zero;
                index = zero;
             }
             else if ((one > zero) && (one > two) && (one > three) && (one > four)
                && (one > five) && (one > six) && (one > seven) && (one > eight)
                && (one > nine)){
                m_curface = Face.One;
                index = one;
             }
             else if ((two > zero) && (two > one) && (two > three) && (two > four)
                && (two > five) && (two > six) && (two > seven) && (two > eight)
                && (two > nine)){
                m_curface = Face.Two;
                index = two;
             }
             else if ((three > zero) && (three > one) && (three > two) && (three > four)
                && (three > five) && (three > six) && (three > seven) && (three > eight)
                && (three > nine)){
                m_curface = Face.Three;
                index = three;
             }
             else if ((four > zero) && (four > one) && (four > two) && (four > three)
                && (four > five) && (four > six) && (four > seven) && (four > eight)
                && (four > nine)){
                m_curface = Face.Four;
                index = four;
             }
             else if ((five > zero) && (five > one) && (five > two) && (five > three)
                && (five > four) && (five > six) && (five > seven) && (five > eight)
                && (five > nine)){
                m_curface = Face.Five;
                index = five;
             }
             else if ((six > zero) && (six > one) && (six > two) && (six > three)
                && (six > four) && (six > five) && (six > seven) && (six > eight)
                && (six > nine)){
                m_curface = Face.Six;
                index = six;
             }
             else if ((seven > zero) && (seven > one) && (seven > two) && (seven > three)
                && (seven > four) && (seven > five) && (seven > six) && (seven > eight)
                && (seven > nine)){
                m_curface = Face.Seven;
                index = seven;
             }
             else if ((eight > zero) && (eight > one) && (eight > two) && (eight > three)
                && (eight > four) && (eight > five) && (eight > six) && (eight > seven)
                && (eight > nine)){
                m_curface = Face.Eight;
                index = eight;
             }
             else if ((nine > zero) && (nine > one) && (nine > two) && (nine > three)
                && (nine > four) && (nine > five) && (nine > six) && (nine > seven)
                && (nine > eight)){
                m_curface = Face.Nine;
                index = nine;
             }
             
             Console.Clear();
             Console.WriteLine("Zero: {0}", zero);
             Console.WriteLine("One: {0}", one);
             Console.WriteLine("Two: {0}", two);
             Console.WriteLine("Three: {0}", three);
             Console.WriteLine("Four: {0}", four);
             Console.WriteLine("Five: {0}", five);
             Console.WriteLine("Six: {0}", six);
             Console.WriteLine("Seven: {0}", seven);
             Console.WriteLine("Eight: {0}", eight);
             Console.WriteLine("Nine: {0}", nine);
             
             if (m_curface != m_lastface){
                m_lastface = m_curface;
                System.Threading.Thread.Sleep(500);
             }
          }
       }
       
       #region Helper methods
       
       public static void Main()
       {
          try
          {
             RunSnippet();
          }
          catch (Exception e)
          {
             string error = string.Format("---\nThe following error occurred while executing the snippet:\n{0}\n---", e.ToString());
             Console.WriteLine(error);
          }
          finally
          {
             Console.Write("Press any key to continue...");
             Console.ReadKey();
          }
       }

       private static void WL(object text, params object[] args)
       {
          Console.WriteLine(text.ToString(), args);   
       }
       
       private static void RL()
       {
          Console.ReadLine();   
       }
       
       private static void Break()
       {
          System.Diagnostics.Debugger.Break();
       }

       #endregion
    }

Advertisement

using System;
using System.Collections.Generic;
using System.Threading;

public class ColumnPick
{
    private static readonly Dictionary<int, int> NumberCount = new Dictionary<int, int>();

    public enum Face { Zero = 0, One = 1, Two, Three, Four, Five, Six, Seven, Eight, Nine };

    public static void Main()
    {
        for (int i = 0; i < 10; i++)
            NumberCount[i] = 0;

        const int maxIndex = 15000;
        var rand = new Random();
        int oldHighest = 0;
        for (int i = 0; i < maxIndex; i++)
        {
            int next = rand.Next(0, 10);
            NumberCount[next]++;

            Console.Clear();
            for (int j = 0; j < 10; j++)
                Console.WriteLine("{0}: {1}", Enum.GetName(typeof(Face), j), NumberCount[j]);

            if (NumberCount[next] > oldHighest)
            {
                oldHighest = NumberCount[next];
                Thread.Sleep(500);
            }
        }
        Console.Write("Press any key to continue...");
        Console.ReadKey();
    }
}

I've simplified the code. Now to find the top x%, just sort the dictionary and take the top x% x 10 number of buckets.

The code in the OP creates a new pseudo-random number generator per toss, seeding it with a clock. This is a terrible idea. Use only one pseudo-random number generator, seed it once and then extract lots of numbers from it: That's how pseudo-random number generators are meant to be used.

As for the question.. Are you asking us how to count?

The question seems to be: Given a horse race, with each horse advancing by a random amount, sample the top ranking horses at any given time.

  • Put the horses into a sorted container.
  • Create an advanceHorses() that moves each horse a random length forward
  • Create a displayHorses(float Percentage) which shows the top desired percentage of the sorted container of horses.
--"I'm not at home right now, but" = lights on, but no ones home

This topic is closed to new replies.

Advertisement