Join us in Outworldz at www.outworldz.com:9000 or follow us:

Search dozens of selected web sites for OpenSim and LSL script

New! Script Meta-Search will search thousands of scripts here and at other sites for LSL or Opensim scripts.
Loading

Want to add a script or a project? Upload it and a half million people will see it and your name here this year.

Home   Show All
Category: Contributor: Creator
Utility Functions Gaussian Random  

Gaussian Random

DESCRIPTION: []::returns a pseudo-random number with Gaussian or normal distribution

Category: Utility Functions
By : GMLscripts.com
Created: 2016-02-26 Edited: 2016-02-26
Worlds: Second Life

the Zip file

Download all files for Gaussian Random
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. [9045 bytes] Run of 300.png
Get file # 2. [50964 bytes] 720px-Normal_Distribution_PDF.svg.png
Get file # 3. Test Script.lsl
1 //:License: Copyright (c) 2007-2015, GMLscripts.com
2 //DESCRIPTION:
3 // This script returns a pseudo-random number with Gaussian or normal distribution, meaning the values returned tend to cluster around a given average or mean value. This could be useful if one needed a random behavior or outcome where deviations from the desired target become more rare as the magnitude of the deviation increases.
4
5 /// An example use might be an enemy AI whose skill is represented by the degree of error in its aiming ability. If a target is at 90 degrees, aim = gauss(90,5) would return a firing direction with a small degree of error. This degree of error (or deviation) is controlled by the second argument. In this case, the value returned would be within 5 degrees (one standard deviation) of the desired direction (the mean) about 68% of the time, and within 10 degrees (two standard deviations) about 95% of the time. The lower the given deviation, the greater chance the returned value will be near the given mean, and the more accurate the aim of the AI would be.
6
7 // just call gauss(mean,deviation) with e value and the error around it
8 //
9 // Returns a pseudo-random number with an exact Gaussian distribution.
10 //
11 // mean mean value of the distribution, real
12 // deviation standard deviation of distribution, real
13
14
15 // Originally from http://www.gmlscripts.com/script/gauss
16 // Copyright (c) 2007-2015, GMLscripts.com
17 // This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
18 // Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
19
20 // 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
21 // 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
22 // 3. This notice may not be removed or altered from any source distribution.
23
24 float x1;
25 float x2;
26 float w;
27
28 float rand(float mean, float deviation)
29 {
30
31 do {
32 x1 = llFrand(2) - 1;
33 x2 = llFrand(2) - 1;
34 w = x1*x1 + x2*x2;
35 } while(0 >= w || w >= 1);
36
37 w = llSqrt(-2 * llLog(w)/w);
38 return mean + deviation * x1 * w;
39 }
40
41 default
42 {
43 // sample test program to prioduce 100 gun rounds aimed at 90 degrees.
44 touch_start(integer total_number)
45 {
46 integer i = 100;
47 while(i-- > 0) {
48 // In the case of the gun shooting at a 90 degree angle, the value returned would be within 5 degrees (one standard deviation) of the desired direction (the mean) about 68% of the time, and within 10 degrees (two standard deviations) about 95% of the time.
49 llSay(0,(string) rand(90,5));
50 }
51 }
52 }

Back to the Best Free Tools in Second Life and OpenSim.