Results 1 to 4 of 4

Thread: TrueRandom Plugin

  1. #1
    Join Date
    Dec 2010
    Posts
    483
    Mentioned
    30 Post(s)
    Quoted
    328 Post(s)

    Default TrueRandom Plugin

    I've been holding off on releasing content to the community solely because I'm running a lot of modified libraries and includes on my end in order to make the scripts I make even possible. A lot of this content isn't quite ready for public release yet, however I am going to begin pushing the finished ones out to the community, this being the first of many.

    Lets examine one of the most fundamental aspects of macroing, random numbers.

    Random numbers *should* be used for any number of things by a developer. Some examples of common uses include:

    Wait random time:
    Simba Code:
    //Waits between 1 and 2 seconds
    Wait(Random(1000, 2000);

    Click random point in box:
    Simba Code:
    //Clicks a random X/Y point in a box specified by X1, X2, Y1, Y2
    ClickMouse(Point(Random(X1, X2), Random(Y1, Y2)), MOUSE_LEFT);

    Offset integer by random number:
    Simba Code:
    //Offsets breaktime by a random amount between -10 and 10
    breakTime := (10 * 60000) + randomRange(-10, 10);

    The examples are endless.

    However, there is a problem. Random numbers, are not truly random. The random number generator you use in simba (or any programming language for that matter) is called a "Pseudo random number generator" meaning they are by no means truly random. In fact, if observed over a period of time, it is more than possible to detect a pattern in the series of random numbers you use.

    This of course is a big problem for us. Jagex are well known for using patterns to detect botting, and its ironic to think that by adding a degree of pseudo-randomness to our scripts we may actually be HELPING them in finding such patterns. Take using a random number to decide whether to left or right click an object. At first, this will be fine, however over a period of time a pattern will start to develop demonstrating when you will left-click and when you will right-click. Scanning for a pattern such as this is much easier than you may believe.

    "So The Bank, what ever will we do!?"

    Simple, we will use truly random numbers!

    True random numbers are calculated by events occurring in real life. Such as atmospheric noise, photonic pressure, and many other "random" anomalies. Obviously including a library to calculate such things on its own would be a massive feat, which is why languages don't ship with the ability. However, people have done it, and they have opened their libraries up to the public.

    Princeton University for example is working on a very interesting concept:
    http://noosphere.princeton.edu/

    What I have done is created a C++ plugin for Simba which will interface with another true random resource, RANDOM.ORG. This plugin makes use of cURL and the libcurl libraries, they have been included with this post. If you would like to compile your own of these binaries, you can download the source and find more information here.

    Installation:

    • Download the ZIP file attached to this post
    • Unzip the file in any directory you would like
    • Copy the contents of the PLUGIN folder your simba plugins folder, copy only the contents not the "PLUGIN" folder itself
    • Copy libcurl.dll, libeay32.dll, libssh2.dll and ssleay32.dll to the same directory as your Simba execuatable (typically C:\Simba\)


    Usage:

    In order to use the plugin in a script, you must first load it:

    Simba Code:
    {$LoadLib TrueRandom}

    After this, Simba will be able to use the new function imported from the plugin.

    Function List:

    Return a truly random number between min and max:
    Simba Code:
    Function trueRandomInt(min, max : Integer) : Integer;

    Return an array of truly random numbers between min and max with a length of size:
    Simba Code:
    Function trueRandomIntArray(min, max, size : Integer) : TIntegerArray;

    Example Script:
    Simba Code:
    {$loadlib TrueRandom}
    var
     I : Integer;
     arr : TIntegerArray;
    begin
      WriteLn('True Random test..');
      WriteLn('Generating 5 random numbers between 0-100...');
      for I := 1 to 5 do
      begin
        WriteLn(IntToStr(trueRandomInt(0, 100)));
      end;
      WriteLn('Generating array of 1000 random numbers between 0-100...');
      arra := trueRandomIntArray(0, 100, 1000);
      for I := 0 to 999 do
      begin
        WriteLn(IntToStr(arra[I]));
      end;
    end.

    Notes:

    Returning an integer with trueRandomInt will take ~700ms. Therefore, it is advised to only use in situations where time is not pertinent. However, this is why I included the trueRandomIntArray function, which also takes ~700ms to execute, however in that time it can generate as many numbers as the array can store, making it equally (if not more) efficient as the pseudo random number generator that you all are used to.

    With this in mind I will quickly demonstrate how to use trueRandomIntArray effectively :

    Simba Code:
    // The following is a script example of cutting a tree
    // It is assumed that you have already found the tree, and created a
    // 10px by 10px bounding box around the point stored in the
    // variable boundingBox : Tbox; and that you wish to click
    // within this box truly randomly
    // Note that since they are identical bounds, you could use one array
    // for both X and Y values.  This example will use 2.
    var
      currentX, currentY, arraySize : Integer;
      possibleX, possibleY : TIntegerArray;
      boundingBox : TBox;

    procedure clickTree();
    begin
      //If below evalutes to true, then we have already used the whole array
      //and need to store another 100 values
      if (currentX > (arraySize - 1)) or (currentY > (arraySize - 1)) then
      begin
        possibleX := trueRandomIntArray(-5, +5, arraySize);
        possibleY := trueRandomIntArray(-5, +5, arraySize);
        //reset element counters as well
        currentX := 0;
        currentY := 0;
      end;
      //click the tree with the next element contents for X and Y
      ClickMouse(possibleX[currentX], possibleY[currentY], MOUSE_LEFT);
      //Increment your X and Y counters so next time it will use different values
      currentX := currentX + 1;
      currentY := currentY + 1;
    end;

    //Main execution
    begin
      //Initialize the arrays to have their values
      arraySize := 100;
      possibleX := trueRandomIntArray(-5, +5, arraySize);
      possibleY := trueRandomIntArray(-5, +5, arraySize);

      //Do the rest of the script below
    end.

    Version 1.1 Update:

    Due to limitations in place by Simba (hopefully this will be corrected soon), you will need to do some allocation work from within Simba to get arrays to function properly from the plugin. Include the following function in your script:

    Simba Code:
    Function SimbaMalloc(Size: Integer): Pointer;
    begin
      Result := AllocMem(Size);
    end;

    And then at the top of your setup do:

    Simba Code:
    SetRandomAllocator(Natify(@SimbaMalloc)); //sets the plugin allocator.

    And you're good to go!!

    Changelog:

    TODO:
    - v2 will feature truly random strings and floating point values as well

    v1.0 - Initial Release
    v1.1 - Stable release, fixed some faulty code that was causing access violations and improper output
    Download:

    The zip containing the most recent binaries can be downloaded as an attachment on this post.

    However the source is also available from a GitHub repo here:
    https://github.com/davi0645/TrueRandom
    Attached Files Attached Files

  2. #2
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Just pointing out that there's also:

    http://www.cplusplus.com/reference/random/

    which includes: http://www.cplusplus.com/reference/r...random_device/

    True random number generator

    A random number generator that produces non-deterministic random numbers, if supported.

    Unlike the other standard generators, this is not meant to be an engine that generates pseudo-random numbers, but a generator based on stochastic processes to generate a sequence of uniformly distributed random numbers. Although, certain library implementations may lack the ability to produce such numbers and employ a random number engine to generate pseudo-random values instead. In this case, entropy returns zero.

    Notice that random devices may not always be available to produce random numbers (and in some systems, they may even never be available). This is signaled by throwing an exception derived from the standard exception on construction or when a number is requested with operator().

    Unless the program really requires a stochastic process to generate random numbers, a portable program is encouraged to use an alternate pseudo-random number generator engine instead, or at least provide a recovery method for such exceptions.

    IF supported (which you can check by seeing if "entropy" returns 0 or catching the thrown exception), this device will use your hardware's thermal noise or other hardware level methods. Requires C++11 and up. Also see: http://en.wikipedia.org/wiki/Hardwar...mber_generator

    From http://en.cppreference.com/w/cpp/num...random_device:

    Note that std::random_device may be implemented in terms of a pseudo-random number engine if a non-deterministic source (e.g. a hardware device) is not available to the implementation.
    Also note: A non-deterministic source does not always have to be hardware. So if you do decide to add this, you'll have to test it.

    Even better if your CPU supports the RDRAND instruction: http://stackoverflow.com/questions/1...c11-and-rdrand
    Last edited by Brandon; 02-19-2015 at 07:55 PM.
    I am Ggzz..
    Hackintosher

  3. #3
    Join Date
    Dec 2010
    Posts
    483
    Mentioned
    30 Post(s)
    Quoted
    328 Post(s)

    Default

    Quote Originally Posted by Brandon View Post
    Just pointing out that there's also:

    http://www.cplusplus.com/reference/random/

    which includes: http://www.cplusplus.com/reference/r...random_device/




    IF supported (which you can check by seeing if "entropy" returns 0 or catching the thrown exception), this device "can" (but does not always need to) use your hardware's thermal noise or other hardware level methods and maybe also software methods. Requires C++11 and up. Also see: http://en.wikipedia.org/wiki/Hardwar...mber_generator
    Interesting read, thank you for that, ultimately its all just different ways of ending up at the same place, which is generating numbers which should be void of any sort of pattern.

    EDIT:

    This plugin should also be supported by any system currently connected to the internet, running Windows of course.

  4. #4
    Join Date
    Dec 2010
    Posts
    483
    Mentioned
    30 Post(s)
    Quoted
    328 Post(s)

    Default

    UPDATE!

    I have updated the original post with binaries for version 1.1

    Big massive up to @Brandon for helping me locate some dirty C code that was causing all sorts of problems. This version represents the first full stable release, with the features of 2.0 still on the way after DXP wraps up.

    I'll update the git repo in a few minutes.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •