10-30-2015, 11:15 AM
(This post was last modified: 08-11-2024, 02:56 PM by DerVVulfman.)
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