Jump to content
  • Others.Random is bugged


    Matenia
    • Product: WRobot General Type: Bug Status: Unconfirmed
    Others.Random(1, 3); // always returns 1
    Others.Random(2, 3); // always returns 2
    //etc

     



    User Feedback

    Recommended Comments

    Matenia

    Posted

    I'm sure this worked on TBC back in the day. Currently definitely broken on Vanilla.

    Droidz

    Posted

    Hi,

    I just tested (on latest version for Vanilla) and it works :

    DFHfpQQMn6.gif

    Matenia

    Posted (edited)

    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
    Droidz

    Posted

    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)

     

    Droidz

    Posted

    and value of 

    (int) DateTime.Now.Ticks

    (I'm not sure robotManager.dll is up to date)

    Matenia

    Posted

    For now, I can't reproduce it anymore (5 minutes ago, It was possible - idk!).
    If I can reproduce it again, I will put the values of Ticks checked and unchecked here.



    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...