DoubleX RMMV Partitioned Random
#1
DoubleX RMMV Partitioned Random

Version: v1.00b

Introduction

* Lets users changes the number of partitions the RNG being run per Math.random() call to control the RNG distributions on the fly

Prerequisites

* Nothing special

Script

Code:
/*============================================================================

 *    ## Plugin Info                                                          
 *----------------------------------------------------------------------------
 *    # Plugin Name                                                           
 *      DoubleX RMMV Partitioned Random                                       
 *----------------------------------------------------------------------------
 *    # Terms Of Use                                                          
 *      You shall keep this plugin's Plugin Info part's contents intact       
 *      You shalln't claim that this plugin's written by anyone other than    
 *      DoubleX or his aliases                                                
 *      None of the above applies to DoubleX or his aliases                   
 *----------------------------------------------------------------------------
 *    # Prerequisites                                                         
 *      Nothing special                                                       
 *----------------------------------------------------------------------------
 *    # Links                                                                 
 *      This script:                                                          
 *      1. http://pastebin.com/FnyDh9mw                                       
*      Mentioned Patreon Supporters:
*      https://www.patreon.com/posts/71738797
 *----------------------------------------------------------------------------
 *    # Author                                                                
 *      DoubleX                                                               
 *----------------------------------------------------------------------------
 *    # Changelog                                                             
 *      v1.00b(GMT 1300 11-11-2015):                                          
 *      1. Added descriptions that will be shown in the plugin manager        
 *      v1.00a(GMT 1300 24-10-2015):                                          
 *      1. 1st version of this plugin finished                                
 *============================================================================*/
/*:
 * @plugindesc Lets users changes the number of partitions the RNG being run per
 *             Math.random() call to control the RNG distributions on the fly
 * @author DoubleX
 *
 * @param parts
 * @desc RNG will be run under each of parts equal-sized partitions
 *       No partition will be run under twice before they've all been run under
 *       parts shouldn't be too large nor too small to maximize the chance for
 *       the RNG generated by Math.random() to be more evenly distributed
 *       Larger parts means more resources(mainly time) needed to run it
 * @default 10
 *
 * @help
 *============================================================================
 *    ## Plugin Call Info                                                     
 *----------------------------------------------------------------------------
 *    # Configuration manipulations                                           
 *      1. DoubleX_RMMV.Partitioned_Random.parts                              
 *         - Returns the value of parts under DoubleX_RMMV.Partitioned_Random
 *      2. DoubleX_RMMV.Partitioned_Random.parts = val                        
 *         - Sets the value of parts under DoubleX_RMMV.Partitioned_Random as
 *           val                                                              
 *         - No DoubleX_RMMV.Formulae_Edit.parts change will be saved         
 *============================================================================
 */

"use strict";
var DoubleX_RMMV = DoubleX_RMMV || {};
DoubleX_RMMV["Partitioned Random"] = "v1.00b";

// The plugin file name must be the same as DoubleX_RMMV.Constants_Edit_File
DoubleX_RMMV.Partitioned_Random_File = "DoubleX RMMV Partitioned Random v100b";

/*============================================================================
 *    ## Plugin Implementations                                               
 *       You need not edit this part as it's about how this plugin works      
 *----------------------------------------------------------------------------
 *    # Plugin Support Info:                                                  
 *      1. Prerequisites                                                      
 *         - Little Javascript coding proficiency to fully comprehend this    
 *           plugin                                                           
 *      2. Function documentation                                             
 *         - The 1st part describes why this function's rewritten/extended for
 *           rewritten/extended functions or what the function does for new   
 *           functions                                                        
 *         - The 2nd part describes what the arguments of the function are    
 *         - The 3rd part informs which version rewritten, extended or created
 *           this function                                                    
 *         - The 4th part informs whether the function's rewritten or new     
 *         - The 5th part informs whether the function's a real or potential  
 *           hotspot                                                          
 *         - The 6th part describes how this function works for new functions
 *           only, and describes the parts added, removed or rewritten for    
 *           rewritten or extended functions only                             
 *         Example:                                                           
 * /*----------------------------------------------------------------------
 *  * Why rewrite/extended/What this function does                         
 *  *----------------------------------------------------------------------*/
/* // arguments: What these arguments are                                     
 * function function_name(arguments) // Version X+; Rewrite/New; Hotspot      
 *     // Added/Removed/Rewritten to do something/How this function works     
 *     function_name_code                                                     
 *     //                                                                     
 * end // function_name                                                       
 *----------------------------------------------------------------------------*/

DoubleX_RMMV.Partitioned_Random = {

    // Stores the param parts that's shown in the plugin manager
    parts: PluginManager.parameters(DoubleX_RMMV.Partitioned_Random_File).parts,

    // An array storing all RNG partitions
    partitions: []

}; // DoubleX_RMMV.Partitioned_Random

Math.random = (function(partitioned_random) { // Hotspot
    return function() {
        // Rewritten to restrict the RNG into an unused partition if any
        var parts = DoubleX_RMMV.Partitioned_Random.parts;
        var used_parts = DoubleX_RMMV.Partitioned_Random.partitions;
        if (used_parts.length >= parts) {
            used_parts.length = 0;
        }
        var part, rng;
        do {
            rng = partitioned_random.apply(this, arguments);
            part = Math.floor(rng * parts);
        } while (used_parts.indexOf(part) !== -1);
        used_parts.push(part);
        return rng;
       //
    };
})(Math.random);

/*============================================================================*/

FAQ

* None so far

Credits and Thanks

* None

Author's Notes

* None so far

Terms and Conditions

* You shall keep this plugin's Plugin Info part's contents intact
* You shalln't claim that this plugin's written by anyone other than DoubleX or his aliases
* None of the above applies to DoubleX or his aliases

Changelog

v1.00b(GMT 1300 11-11-2015):
1. Added descriptions that will be shown in the plugin manager
v1.00a(GMT 1300 24-10-2015):
1. 1st version of this script finished
My RMVXA/RMMV/RMMZ scripts/plugins:
http://rpgmaker.net/users/DoubleX/scripts/
Reply }


Possibly Related Threads…
Thread Author Replies Views Last Post
   DoubleX RMMV Popularized ATB Compatibility DoubleX 16 23,100 12-26-2022, 06:17 AM
Last Post: DoubleX
   DoubleX RMMV Confusion Edit DoubleX 3 7,623 09-09-2022, 11:12 AM
Last Post: DoubleX
   DoubleX RMMV Popularized ATB Clock DoubleX 2 6,465 03-25-2022, 01:04 PM
Last Post: DoubleX
   DoubleX RMMV Status Bars Compatibility DoubleX 0 1,908 02-06-2022, 07:56 AM
Last Post: DoubleX
   DoubleX RMMV Popularized ATB Bar DoubleX 3 8,560 05-19-2021, 06:10 AM
Last Post: DoubleX
   DoubleX RMMV Skill Hotkeys DoubleX 2 5,989 02-13-2021, 04:59 AM
Last Post: DoubleX
   DoubleX RMMZ Skill Item Cooldown DoubleX 4 6,111 02-07-2021, 04:11 PM
Last Post: DoubleX
   DoubleX RMMZ Skill Item Triggers DoubleX 3 5,556 12-26-2020, 04:00 PM
Last Post: DoubleX
   DoubleX RMMZ TPBS Configurations Edit DoubleX 3 5,660 12-25-2020, 12:30 PM
Last Post: DoubleX
   DoubleX RMMV Superlative ATB DoubleX 2 4,458 12-11-2020, 02:25 PM
Last Post: DoubleX



Users browsing this thread: 1 Guest(s)