Jump to content
  • Others.Random is bugged


    Matenia
    • Product: WRobot General Type: Bug Status: Unconfirmed
     Share

    Others.Random(1, 3); // always returns 1
    Others.Random(2, 3); // always returns 2
    //etc

     


     Share


    User Feedback

    Recommended Comments

    I did the same test yesterday (exact same in development tools). Maybe it was a bad seed or something. My computer had already been running all day.

    Edit: Just did it again and it still always reports 1 - this is WRobot 32758. 

    I can get it to work if I execute it before even starting the bot (Quester). If I use it while the bot is running without ever using it before, it will ALWAYS result in 1.
    For now, I just made my own implementation in my quester profile to work around.

    Edited by Matenia
    Link to comment
    Share on other sites

    Random code is simple 

            internal static readonly Random Rng = new Random(unchecked((int)DateTime.Now.Ticks));
    
            /// <summary>
            /// Return Random number.
            /// </summary>
            /// <param name="from">From.</param>
            /// <param name="to">To.</param>
            /// <returns>System.Int32.</returns>
            public static int Random(int from, int to)
            {
                try
                {
                    return Rng.Next(from, to + 1);
                }
                catch (Exception exception)
                {
                    Logging.WriteError("Random(int from, int to): " + exception);
                }
                return 0;
            }

    What is your value of 

    unchecked((int)DateTime.Now.Ticks)

     

    Link to comment
    Share on other sites



    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

×
×
  • Create New...