Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* double random_normal(mean, standard_deviation);
- * Implements the Polar form of the Box-Muller Transformation
- *
- * © Copyright 1994, Everett F. Carter Jr.
- * Ported to GML by Tsa05
- * Slightly modified by Dragonite (Dimenticare on Pastebin)
- * Permission is granted by the author to use
- * this software for any application provided this
- * copyright notice is preserved.
- *
- * Recall that numbers beyond the Standard Deviation
- * are possible (just not probable), and should be accounted for.
- *
- */
- var m, s;
- m=argument0;
- s=argument1;
- var x1, x2, w, y1;
- w=2;
- while ( w >= 1.0 ){
- x1 = 2.0 * random(1) - 1.0;
- x2 = 2.0 * random(1) - 1.0;
- w = x1 * x1 + x2 * x2;
- }
- var r;
- r=m+(x1*(sqrt((-2.0*ln(w))/w)))*s;
- if (r>0)
- return r;
- return random_normal(argument0, argument1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement