PDA

View Full Version : humanness random



g0tp0t
11-11-2010, 09:21 PM
i thought abouty random in a random, which i have used quite often. i decided to plot the ouput to see what the real probability was and it is exactly what i thought. its not a guassian function but it look human. try it:

{$i srl/srl.scar}
var b ,r,a,i: integer;
begin
b := CreateBitmap(200,200);
for i := 0 to 5000 do
begin
a := random(360);
r := round(random(random(100)));
FastSetPixel(b,round(r*cos(a))+100,round(r*sin(a)) +100,clRed);
end;
DrawBitmapDebugImg(b);
DisplayDebugImgWindow(200,200);
end.

Cstrike
11-12-2010, 12:35 AM
Is this Simba or SCAR code (you listed it as Simba code)? Crashes my Simba, and I uninstalled SCAR.

Overtime
11-12-2010, 01:29 AM
IT looks simba as scar dont use $ iirc

Cstrike
11-12-2010, 01:55 AM
IT looks simba as scar dont use $ iirc

Crap, didn't notice that (I take it for granted xD)

EDIT:
http://img18.imageshack.us/img18/5189/nicedm.jpg
Why did I chose JPEG... ugh

Either way, for some reason it now works :)


EDIT2: This was fun to play around with:
{$i srl/srl.scar}
var b, t,r,a,i: integer;
begin
MarkTime(t);
repeat
b := CreateBitmap(200,200);
for i := 0 to 0 do
begin
a := random(360);
r := round(random(random(100)));
FastSetPixel(b,round(r*cos(a))+100,round(r*sin(a)) +100,clRed);
end;
DrawBitmapDebugImg(b);
DisplayDebugImgWindow(200,200);
FreeBitmap (b);
until (TimeFromMark(t) > 10000)
end.

moparisthebest
11-12-2010, 02:18 PM
But using a random inside another random is really redundant, if the function is truly random like it supposed to be (it's not, but thats for another thread) then random(random(100)) should return the same results over a period of calls as random(100). Try your code just doing it once instead of twice and see if they are the same or not.

Cstrike
11-12-2010, 06:21 PM
But using a random inside another random is really redundant, if the function is truly random like it supposed to be (it's not, but thats for another thread) then random(random(100)) should return the same results over a period of calls as random(100). Try your code just doing it once instead of twice and see if they are the same or not.

The difference is not too significant, but with the graph generated, it looks much more real (relative to human tendancies) with two randoms than one random.

g0tp0t
11-13-2010, 12:07 AM
no
ther is a big big difference
i have continually updated the script and hers is my finished script. the color of the pixels represents how many times that point was called. the more randoms i use, the closer most points are to center =]

{$i srl/srl.scar}
var b ,r,a,i,col,increment: integer;ch,cs,cl:extended;
begin
increment := 10;
ClearDebugImg;
b := CreateBitmap(200,200);
while not iskeydown(VK_RCONTROL) do
begin
for i := 0 to 1000 do
begin
a := random(360);
r := round(random(random(random(100))));
col := FastGetPixel(b,round(r*cos(a))+100,round(r*sin(a)) +100);
ColorToHSL(col,ch,cs,cl);
cl := 50
FastSetPixel(b,round(r*cos(a))+100,round(r*sin(a)) +100,HSLtoColor(mine(99-increment,ch+increment),100,mine(cl,50)));
end;
DrawBitmapDebugImg(b);
DisplayDebugImgWindow(200,200);
end;
FreeBitmap(b);
//FreeBitmap(GetDebugBitmap);
end.

this is one of the things i have used in my scripts for a wiule :P

it works because the output of the first random becomes the input for the next, so a lower number is more likely to be called. the second random has a lower range than the first.

g0tp0t
11-13-2010, 12:19 AM
to make it easier for people to change the number of randoms used i changed the script( again >.<)

here is new one. lol :{$i srl/srl.scar}
var b ,r,a,i,col,increment,randn,randi: integer;ch,cs,cl:extended;
const
randcount=3;
begin
increment := 10;
ClearDebugImg;
b := CreateBitmap(200,200);
while not iskeydown(VK_RCONTROL) do
begin
for i := 0 to 1000 do
begin
a := random(360);
randn := 100;
for randi := 0 to randcount do
randn := random(randn);
r := random(random(random(100)));
col := FastGetPixel(b,round(r*cos(a))+100,round(r*sin(a)) +100);
ColorToHSL(col,ch,cs,cl);
cl := 50
FastSetPixel(b,round(r*cos(a))+100,round(r*sin(a)) +100,HSLtoColor(mine(99-increment,ch+increment),100,mine(cl,50)));
end;
DrawBitmapDebugImg(b);
DisplayDebugImgWindow(200,200);
end;
FreeBitmap(b);
end.

Feroc1ty
11-13-2010, 01:47 AM
Pretty redundant, so many operations and assignments done for a simple random...

Many better methods of doing this ranging from from using simple mathematical operators to going into more complex methods such as seeding the random yourself (not sure if this is possible in simba/scar.)

Zyt3x
11-13-2010, 10:41 AM
http://img517.imageshack.us/img517/6199/capture025.png
The first is with Random(100), the second is with Random(Random(100)) ran for about 5 seconds.

http://img401.imageshack.us/img401/8080/capture026.png
Same as above, ran for 1 minute and 15 seconds

var b ,r,a,i,col,increment,randn,randi,t: integer;ch,cs,cl:extended;
const
randcount=3;
begin
t := getsystemtime;
increment := 10;
ClearDebugImg;
b := CreateBitmap(400,200);
DisplayDebugImgWindow(400,200);
while not iskeydown(VK_RCONTROL) do
begin
for i := 0 to 1000 do
begin
a := random(360);
randn := 100;
for randi := 0 to randcount do
randn := random(randn);
r := random(random(100));
col := FastGetPixel(b,round(r*cos(a))+100,round(r*sin(a)) +100);
ColorToHSL(col,ch,cs,cl);
cl := 50
FastSetPixel(b,round(r*cos(a))+100,round(r*sin(a)) +100,HSLtoColor(mine(99-increment,ch+increment),100,mine(cl,50)));
end;
for i := 0 to 1000 do
begin
a := random(360);
randn := 100;
for randi := 0 to randcount do
randn := random(randn);
r := random(random(random(100)));
col := FastGetPixel(b,round(r*cos(a))+100,round(r*sin(a)) +100);
ColorToHSL(col,ch,cs,cl);
cl := 50
FastSetPixel(b,200+(round(r*cos(a))+100),round(r*s in(a))+100,HSLtoColor(mine(99-increment,ch+increment),100,mine(cl,50)));
end;
DrawBitmapDebugImg(b);
end;
FreeBitmap(b);
writeln(getsystemtime-t);
end.

Narcle
11-13-2010, 04:30 PM
I don't feel like doing it but someone should compare Random(1000)/Random(10000) to Random(Random(100)).

marpis
11-13-2010, 11:55 PM
Random(Random(100)) Ofcourse! That's so brilliant!

Line 1: Random(1) = 0
Line 2: Random(2) = 0, 1
Line 3: Random(3) = 0, 1, 2
Line 4: Random(4) = 0, 1, 2, 3
Line 5: Random(5) = 0, 1, 2, 3, 4

Imagine you pick one of the lines. Just a random line.
After that you pick a random number listed in the series in the line.
Number 0 is always a possible pick, but number 1 is only available in 4 lines.
Number 2 is available in 3 lines. Number 4 is only available in one line.

Chance to get number 0 = 5 / 15 = 0.333
Chance to get number 1 = 4 /15 = 0.267
Chance to get number 2 = 3 / 15 = 0.200
Chance to get number 3 = 2 / 15 = 0.133
Chance to get number 4 = 1 / 15 = 0.067

Ergo the smaller the number, the higher the chance it occurs!
Perfect humanlike randomness! :)
So simple and none of us had thought of this yet.

Great find, rep++

moparisthebest
11-14-2010, 01:49 AM
Come to think about it, random(random(100)) would statistically be closer to something like random(75) or something similar. A mathematician could figure this out to exact numbers, but I'm not a mathematician, nor do I have the time. All I can tell you is calling random more times doesn't really help you.

Zyt3x
11-14-2010, 01:54 AM
well... random(random(100)) would sometimes get 99, while random(75) cant go higher than 74...

moparisthebest
11-14-2010, 01:58 AM
well... random(random(100)) would sometimes get 99, while random(75) cant go higher than 74...

That's true, but the spread would look closer to the distributions that you guys have posted further up.

Feroc1ty
11-14-2010, 04:52 AM
The mathematical functions could do same thing with less operations, or am I mistaken?

marpis
11-14-2010, 09:22 AM
Come to think about it, random(random(100)) would statistically be closer to something like random(75) or something similar. A mathematician could figure this out to exact numbers, but I'm not a mathematician, nor do I have the time. All I can tell you is calling random more times doesn't really help you.

Check out my thinking above, random(random(100)) will produce more small numbers than big ones. random(100) will produce the same amount of each number.

Zyt3x
11-14-2010, 12:09 PM
http://img4.imageshack.us/img4/5282/capture027.png
random(random(100)), random(75)

moparisthebest
11-14-2010, 04:00 PM
Check out my thinking above, random(random(100)) will produce more small numbers than big ones. random(100) will produce the same amount of each number.

How is that any more human though? It's different, that doesn't really make it more human though.

marpis
11-14-2010, 06:12 PM
How is that any more human though? It's different, that doesn't really make it more human though.

That way you will most likely click to the center of an area, and clicking far away from the center is unlikely but still possible, just like a human clicks.

Bad Boy JH
11-15-2010, 03:31 AM
however, it stilll doesn't take into account one thing i recon needs to be taken into account....the starting mouse position, if your mouse is above the button, you are probably going to click the upper portion of the button...

Cstrike
11-15-2010, 03:42 AM
however, it stilll doesn't take into account one thing i recon needs to be taken into account....the starting mouse position, if your mouse is above the button, you are probably going to click the upper portion of the button...

What if the human overshoots by accident in real life?
As a cool test, I tried moving my cursor to the word "still" in the quote above from the left hand side, I ended up overshooting it ;)

As such, that is just me though. Everyone is different

weequ
11-15-2010, 02:55 PM
I decided to graph the radius with million instances.
Also did the same with a random gaussian value generating function:
http://img602.imageshack.us/img602/4636/curves.jpg

Zyt3x
11-15-2010, 03:19 PM
I think that gaussian random function looks extremely similar to a cosine / sine graph...
http://img197.imageshack.us/img197/2316/capture028.png
var I : Integer;
begin
for I := -3 to 36 do
WriteLn((Cos(Radians(I*5))+1)*100);
end.

Cstrike
11-15-2010, 03:53 PM
I think that gaussian random function looks extremely similar to a cosine / sine graph...
http://img197.imageshack.us/img197/2316/capture028.png
var I : Integer;
begin
for I := -3 to 36 do
WriteLn((Cos(Radians(I*5))+1)*100);
end.


You what might be good about the sine graph?
It could be set up so that the dead center has sort of a valley started, therefore meaning that the player won't click dead center all the time as well

g0tp0t
11-16-2010, 12:22 AM
lol, TY marpis for your explantion :P i cant explain anyuthing very well :P

i had thought about using numbers but i didnt now where to start. lol. also ty for pics. i was too lazy to screen shot. also uber ty for rep >.<

sin and cosine arent very cpu intensive so they seem an even better alternative.

Feroc1ty
11-16-2010, 09:12 PM
procedure ClickBox(box:TBox);
var x,y:integer;
begin
x := (box.x2 - box.x1)/2;
y := (box.y2 - box.y1)/2;
Mouse(box.x1 + x + Random(RandomRange(-x,x)), box.y1 + y + Random(RandomRange(-y,y)), 0, 0, true);
end;

g0tp0t
11-16-2010, 10:04 PM
you use a randomrange in a random, so the output of the random range will not include a minimum. you will get numbers under the munimum so you need randomrange in randomrange :P

EDIT: nvm i just glanced at your code. i didnt realise it was just opposite of centerx :P

Feroc1ty
11-16-2010, 10:05 PM
No clue what you just said but I'm pretty sure my function should work although I haven't tested it.

g0tp0t
11-16-2010, 10:12 PM
lol. i told you im bad at explaining :P. but yea, i looked at your code quickly and thought you misunderstood the concept. i was thinking that random(randomrange(10,100) and randomrange(randomrange(10,100),100) or randomrange(100,randomrange(10,100)) or even randomrange(randomrange(10,100),randomrange(10,100 )) were what you meant to use :P

Feroc1ty
11-16-2010, 10:17 PM
My code finds the dimensions of the box, than adds a random(randomrange()) to the midpoint of the box, and as far as I know Random( RandomRange(-x,x) ) should work perfectly, since the x/y variable is 1/2 the dimension of the box and it's being added (or subtracted) to the midpoint.

Please point out the mistake if you do find my code to be incorrect though, since I'm using it in one of my scripts in the making.

g0tp0t
11-17-2010, 12:59 AM
no, i think its fine :P i just didnt realize at first what you were doing because i just glanced. =]
EDIT: lol, im glad my idea is already being put to use :P