PDA

View Full Version : lotz of hard work right here (new include)



lardmaster
10-07-2006, 02:39 AM
tbis is a very cool include kinda think, it generates random numbers based on a gaussian (or normal) distribution. (google gaussian distribution on me (http://www.google,com)) use the function gaussianbox(...,...,...,...) to click inside a box, but randomly and more likely towards the center. i am hoping for this to be included in the next version of srl, and i will update it very soon. enjoy!

ps, i dont remember if there is rep on srl but if there is, ++ :D

wow, oops no attachment, what, no attachments allowed! (fixed, thnx dankness)
ppps, wow, its size doesnt remind me of how huge of a job it was to make... kinda new to pascal...


fine, dont leave comments, see if i care, i still updated the code...again...(just include this, not srl, this includes srl).

THIS IS ALL OUT OF DATE, GO TO COMPLETE REVAMP INSTEAD

magnetical
10-07-2006, 04:31 AM
Sounds like it would be a good script... probably good for random movements :D

Flyboy
10-07-2006, 04:32 AM
This just uses your code and shows its result... please run the code below and tell me if the results give a Normal Distribution (or gaussian distribution (which looks the same;)))

Someone please post thier result... thanks (you should get at least 30,000 in your sample to show a reasonable level of confidence in your results)


{.include \srl\srl.scar}
function findgaussian(min, max : integer) : integer;
var
values : array[-16..16] of extended;
e, a, mypi, b, total, selected:extended;
i,margin : integer;

begin
e := 2.718281828
mypi := 3.1415926535897932354626433832795 {from memory}
a := 2*mypi;
a := sqrt(a);
i := 1;
b := 1875;
b := b/10000;

for i:=-16 to 16 do
values[i] := pow(e, -pow((b*i),2)/2)/a;

selected := random(4919578);
selected:=selected/1000000;
i:=-16;
total:=0;
while(i<=16) and (selected > total) do
begin
total := total+values[i];
i:=i+1;
end
margin:= (max-min)/32;
Result := random(margin)+margin*(i+16)+min;
if margin=0 then
Result:=random(max-min)+min;
end;

procedure TestFindGaussian(TotalNum: Integer);
var
i, temp, count: Integer;
Num: Array of Integer;

begin
setarraylength(Num, TotalNum);
repeat
Count := Count + 1;
temp := findgaussian(0, (TotalNum));
Num[temp] := Num[temp] + 1;
if Count mod 1000 = 0 then
begin
ClearDebug;
Writeln('Result in % press q to quiet Total sample size: ' + inttostr(Count));
for i := 0 to (TotalNum - 1) do
begin
writeln(inttostr(i) + ' --> ' + inttostr(round(Num[i]/Count*100)) + '%');
end;
writeln('');
end;
until IsKeyDown('q') or IsKeyDown('Q');
end;

begin
TestFindGaussian(strtoint(Readln('Total number of digets to test (try 10)')));
end.

lardmaster
10-07-2006, 03:22 PM
alright flyboy, added your function, ps, for your tester, there has to be at least 32 digits or it will not be gaussian at all

lardmaster
10-07-2006, 03:27 PM
Result in % press q to quiet Total sample size: 31000
0 --> 0%
1 --> 0%
2 --> 0%
3 --> 0%
4 --> 0%
5 --> 0%
6 --> 0%
7 --> 0%
8 --> 0%
9 --> 0%
10 --> 0%
11 --> 0%
12 --> 0%
13 --> 0%
14 --> 0%
15 --> 0%
16 --> 0%
17 --> 0%
18 --> 0%
19 --> 0%
20 --> 0%
21 --> 0%
22 --> 1%
23 --> 0%
24 --> 1%
25 --> 1%
26 --> 1%
27 --> 1%
28 --> 1%
29 --> 1%
30 --> 1%
31 --> 1%
32 --> 1%
33 --> 1%
34 --> 1%
35 --> 1%
36 --> 2%
37 --> 2%
38 --> 2%
39 --> 2%
40 --> 2%
41 --> 2%
42 --> 2%
43 --> 2%
44 --> 2%
45 --> 3%
46 --> 2%
47 --> 2%
48 --> 3%
49 --> 3%
50 --> 3%
51 --> 3%
52 --> 3%
53 --> 3%
54 --> 3%
55 --> 3%
56 --> 3%
57 --> 2%
58 --> 3%
59 --> 3%
60 --> 2%
61 --> 2%
62 --> 2%
63 --> 2%
64 --> 2%
65 --> 2%
66 --> 2%
67 --> 2%
68 --> 2%
69 --> 1%
70 --> 1%
71 --> 1%
72 --> 1%
73 --> 1%
74 --> 1%
75 --> 0%
76 --> 0%
77 --> 0%
78 --> 0%
79 --> 0%
80 --> 0%
81 --> 0%
82 --> 0%
83 --> 0%
84 --> 0%
85 --> 0%
86 --> 0%
87 --> 0%
88 --> 0%
89 --> 0%
90 --> 0%
91 --> 0%
92 --> 0%
93 --> 0%
94 --> 0%
95 --> 0%
96 --> 0%
97 --> 0%
98 --> 0%
99 --> 0%

its crazy how close it is to what youd expect, by the way, it samples from 3 standard deviations.
Result in % press q to quiet Total sample size: 109000
0 --> 0%
1 --> 0%
2 --> 0%
3 --> 0%
4 --> 0%
5 --> 1%
6 --> 1%
7 --> 1%
8 --> 2%
9 --> 3%
10 --> 3%
11 --> 4%
12 --> 5%
13 --> 6%
14 --> 7%
15 --> 8%
16 --> 8%
17 --> 8%
18 --> 8%
19 --> 8% q
20 --> 7%
21 --> 6%
22 --> 5%
23 --> 4%
24 --> 3%
25 --> 0%
26 --> 0%
27 --> 0%
28 --> 0%
29 --> 0%
30 --> 0%
31 --> 0%

Flyboy
10-07-2006, 05:25 PM
What do you get when you use smaller numbers like you would in the game (12 or less)

ilikegrapesoda72
10-07-2006, 05:51 PM
...That is a very confusing script... Then it must be good lol (I don't know)

lardmaster
10-07-2006, 06:35 PM
it just does random, i could do it to work with smaller numbers, if you want, like how small would it really matter if its truly gaussian?

Flyboy
10-07-2006, 08:56 PM
The proplem I see is that it is only a normal distribution for a larger range. Smaller ranges give the same results as random()

Result in % press q to quiet Total sample size: 64000
0 --> 5%
1 --> 5%
2 --> 5%
3 --> 5%
4 --> 5%
5 --> 5%
6 --> 5%
7 --> 5%
8 --> 5%
9 --> 5%
10 --> 5%
11 --> 5%
12 --> 5%
13 --> 5%
14 --> 5%
15 --> 5%
16 --> 5%
17 --> 5%
18 --> 5%
19 --> 5%
q
Successfully executed

Possibly consider using a variable for the variance (http://en.wikipedia.org/wiki/Variance). I suspect for a lot of our uses a variance (http://en.wikipedia.org/wiki/Variance) of 0.2 - 0.6 would be appropriate

lardmaster
10-07-2006, 10:28 PM
i told you, only 32 and above is normal, for how small would you like it to work.

Flyboy
10-08-2006, 01:25 AM
i told you, only 32 and above is normal, for how small would you like it to work.sorry, I should have rescaned all the posts above prior to making comments...

I would think you should make it accomidate all sizes of box to click within... That way a person could use it 100% of the time regaurdless of the box size needed.

A typical application requiring a small value would be clicking within option boxes and 'Click to Continue', the box will have a large x value and smal y value .

EDIT:
Hmmmm if you have it print the total for each number Num[i] you will descover a huge hole in your math... sorry

lardmaster
10-08-2006, 08:43 PM
???

Flyboy
10-09-2006, 07:12 AM
There is no fancy math here, just simple logic. What do you think?

lardmaster
10-09-2006, 09:52 PM
your logic makes no sense to me, see my other post about the complete revam, the method is so simple it will astound you (plz explain your program)

Flyboy
10-09-2006, 10:20 PM
just compare results. I just made a sliding odds system which creates a nice bell curve and can handle numbers from 0 to 100 easily. I'm sure a more simple formula could do what I just did, that's why I posted... its stll bulky and could be cut down a lot.

I've been thinking if we just make a function which takes one number (lets say RandNum: Integer) in and returns it using 0 as the mean with its extreams being +/- RandNum. This will lend itself to fit into the existing MMouse function. Thus changing up the Mouse function since it just calls MMouse. :)

lardmaster
10-10-2006, 10:29 PM
just compare results. I just made a sliding odds system which creates a nice bell curve

slidiing odds system??? i didnt know that odd numbers were so tangible that you could just slide em on down. your program is very complex and the system it uses strange variable names, which do not quite make sense for thier use. offset? this does not seem like it should equal the square of the maximum number plus 1. whats all this stuff with maxnumber +1?

Boreas
10-10-2006, 11:24 PM
It's not odd numbers. Wait til you take a stat class, until then don't worry about it.

Flyboy
10-11-2006, 12:57 AM
slidiing odds system??? i didnt know that odd numbers were so tangible that you could just slide em on down. your program is very complex and the system it uses strange variable names, which do not quite make sense for thier use. offset? this does not seem like it should equal the square of the maximum number plus 1. whats all this stuff with maxnumber +1?
lol - yes there is a bit of strangness going on here. The wird variable names is cause this started as a full mouse() repacement, then got refined to just returning a normally distributed number. Since different formulas are needed for small numbers and big numbers, I just took a page from simulator building in spread sheets, where the objective is results not clean formulas. Thus it looks a lot more complicated than it is... I just splashed my thoughts onto SCAR and then tweaked till it gave the results I was after :) Here is the scivey on the logic behind it:

Step 1:
Take the first number 0 and put it in a lotter where its chance of winning is 1:MaxNumber^2
if there is a winner... great we are done

Step 2:
Take the first two numbers (0 ,1) and put them in a lottery with odds 1:(MaxNumber^2 - MaxNumber)
if ether number wins... great we are done

Step 3:
Take the first three numbers (0, 1, 2) put them in a lottery with odds 1:(MaxNumber^2 - (MaxNumber * 2))
if there is a winner... great we are done

Step 4:
Keep doing as above till you reach MaxNumber

Step 5:
Randomly change the number to a negative number 50% of the time

Step 6:
if the answer is 0 then 50% of the time goto Step 1 the other 50% of the time... great we are done

Step 7:
For some reason every now and then I got a wierd huge number so I added a failsafe which checks if the number is beyond the possible range and if it is just use Random(MaxNumber) - very sloppy but given the frequency of this occurance, it does not statistically affect the results.

If any of you have the time or care to please clean up this code and make it more cpu friendly, this is ok for small numbers ( less than 100) but gets cpu intensive for big numbers as the number of itterations gets huge as the number increases.

lardmaster
10-12-2006, 01:15 AM
but why does this make a bell curve, to me it just seems to make a bunch of random lotterys ;(, check out my new gaussian procedure though

Flyboy
10-16-2006, 07:13 AM
Sorry to be blunt, but who's formula did you rip. I'm having doubts at the moment if it is your original work since your having trouble understanding the concept of sliding odds. There's noting wrong with googling formulas and adapting them to our purposes in SCAR, but passing yourself off as a math wizz when you don't understand the formula your using does not make sence to me.

P.S. Ok just re-read that... seemed a bit harsh. I do love what your trying to do, just feeling a little like im been conned. ;)

P.P.S. I just Re-re-read the above and decided I'm just in a bad :fiery: mood... please disregaurd the whole post :confused:

lardmaster
10-16-2006, 06:38 PM
its ok, the first program, i completely concieved by my self. the second one, i got from a website that said "how to make a gaussian distribution random number generator" so im assuming that they put it up there for other people to use the idea. and no, i am not a math wiz :(, but i do know a fair amount, i just havent taken any statistical mechanics classes, so i really dont understand the formula i am using... :(. but the algorithm for doing logorithms...i am proud of, i understand completely! :)

Flyboy
10-17-2006, 03:37 AM
Thanks... I'm having one of those "BAD" weeks of my life... and I'm not talking about trivial stuff like a bad report card ether. Sorry if I took some of it out on you :)

lardmaster
10-17-2006, 09:10 PM
hmmm. i posted yesterday, but it isnt there, basicly, the first one was mine, the second one i googled, but i am proud of my ln finder which i did on my own. and no i not math wiz but i pretty good and not taken any statistical classes