Advertisement
Double_X

DoubleX RMMV Partitioned Random v100b

Oct 24th, 2015 (edited)
486
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*============================================================================
  2.  *    ## Plugin Info                                                          
  3.  *----------------------------------------------------------------------------
  4.  *    # Plugin Name                                                          
  5.  *      DoubleX RMMV Partitioned Random                                      
  6.  *----------------------------------------------------------------------------
  7.  *    # Terms Of Use                                                          
  8.  *      You shall keep this plugin's Plugin Info part's contents intact      
  9.  *      You shalln't claim that this plugin's written by anyone other than    
  10.  *      DoubleX or his aliases                                                
  11.  *      None of the above applies to DoubleX or his aliases                  
  12.  *----------------------------------------------------------------------------
  13.  *    # Prerequisites                                                        
  14.  *      Nothing special                                                      
  15.  *----------------------------------------------------------------------------
  16.  *    # Links                                                                
  17.  *      This script:                                                          
  18.  *      1. http://pastebin.com/FnyDh9mw                                      
  19.  *      Mentioned Patreon Supporters:
  20.  *      https://www.patreon.com/posts/71738797
  21.  *----------------------------------------------------------------------------
  22.  *    # Author                                                                
  23.  *      DoubleX                                                              
  24.  *----------------------------------------------------------------------------
  25.  *    # Changelog                                                            
  26.  *      v1.00b(GMT 1300 11-11-2015):                                          
  27.  *      1. Added descriptions that will be shown in the plugin manager        
  28.  *      v1.00a(GMT 1300 24-10-2015):                                          
  29.  *      1. 1st version of this plugin finished                                
  30.  *============================================================================*/
  31. /*:
  32.  * @plugindesc Lets users changes the number of partitions the RNG being run per
  33.  *             Math.random() call to control the RNG distributions on the fly
  34.  * @author DoubleX
  35.  *
  36.  * @param parts
  37.  * @desc RNG will be run under each of parts equal-sized partitions
  38.  *       No partition will be run under twice before they've all been run under
  39.  *       parts shouldn't be too large nor too small to maximize the chance for
  40.  *       the RNG generated by Math.random() to be more evenly distributed
  41.  *       Larger parts means more resources(mainly time) needed to run it
  42.  * @default 10
  43.  *
  44.  * @help
  45.  *============================================================================
  46.  *    ## Plugin Call Info                                                    
  47.  *----------------------------------------------------------------------------
  48.  *    # Configuration manipulations                                          
  49.  *      1. DoubleX_RMMV.Partitioned_Random.parts                              
  50.  *         - Returns the value of parts under DoubleX_RMMV.Partitioned_Random
  51.  *      2. DoubleX_RMMV.Partitioned_Random.parts = val                        
  52.  *         - Sets the value of parts under DoubleX_RMMV.Partitioned_Random as
  53.  *           val                                                              
  54.  *         - No DoubleX_RMMV.Formulae_Edit.parts change will be saved        
  55.  *============================================================================
  56.  */
  57.  
  58. "use strict";
  59. var DoubleX_RMMV = DoubleX_RMMV || {};
  60. DoubleX_RMMV["Partitioned Random"] = "v1.00b";
  61.  
  62. // The plugin file name must be the same as DoubleX_RMMV.Constants_Edit_File
  63. DoubleX_RMMV.Partitioned_Random_File = "DoubleX RMMV Partitioned Random v100b";
  64.  
  65. /*============================================================================
  66.  *    ## Plugin Implementations                                              
  67.  *       You need not edit this part as it's about how this plugin works      
  68.  *----------------------------------------------------------------------------
  69.  *    # Plugin Support Info:                                                  
  70.  *      1. Prerequisites                                                      
  71.  *         - Little Javascript coding proficiency to fully comprehend this    
  72.  *           plugin                                                          
  73.  *      2. Function documentation                                            
  74.  *         - The 1st part describes why this function's rewritten/extended for
  75.  *           rewritten/extended functions or what the function does for new  
  76.  *           functions                                                        
  77.  *         - The 2nd part describes what the arguments of the function are    
  78.  *         - The 3rd part informs which version rewritten, extended or created
  79.  *           this function                                                    
  80.  *         - The 4th part informs whether the function's rewritten or new    
  81.  *         - The 5th part informs whether the function's a real or potential  
  82.  *           hotspot                                                          
  83.  *         - The 6th part describes how this function works for new functions
  84.  *           only, and describes the parts added, removed or rewritten for    
  85.  *           rewritten or extended functions only                            
  86.  *         Example:                                                          
  87.  * /*----------------------------------------------------------------------
  88.  *  * Why rewrite/extended/What this function does                        
  89.  *  *----------------------------------------------------------------------*/
  90. /* // arguments: What these arguments are                                    
  91.  * function function_name(arguments) // Version X+; Rewrite/New; Hotspot      
  92.  *     // Added/Removed/Rewritten to do something/How this function works    
  93.  *     function_name_code                                                    
  94.  *     //                                                                    
  95.  * end // function_name                                                      
  96.  *----------------------------------------------------------------------------*/
  97.  
  98. DoubleX_RMMV.Partitioned_Random = {
  99.  
  100.     // Stores the param parts that's shown in the plugin manager
  101.     parts: PluginManager.parameters(DoubleX_RMMV.Partitioned_Random_File).parts,
  102.  
  103.     // An array storing all RNG partitions
  104.     partitions: []
  105.  
  106. }; // DoubleX_RMMV.Partitioned_Random
  107.  
  108. Math.random = (function(partitioned_random) { // Hotspot
  109.     return function() {
  110.         // Rewritten to restrict the RNG into an unused partition if any
  111.         var parts = DoubleX_RMMV.Partitioned_Random.parts;
  112.         var used_parts = DoubleX_RMMV.Partitioned_Random.partitions;
  113.         if (used_parts.length >= parts) {
  114.             used_parts.length = 0;
  115.         }
  116.         var part, rng;
  117.         do {
  118.             rng = partitioned_random.apply(this, arguments);
  119.             part = Math.floor(rng * parts);
  120.         } while (used_parts.indexOf(part) !== -1);
  121.         used_parts.push(part);
  122.         return rng;
  123.        //
  124.     };
  125. })(Math.random);
  126.  
  127. /*============================================================================*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement