SRL Archive - Test corner

Pseudo-Random generator. Better for scripts?


m0u53m4t

2007-02-24 16:48:58

I was thinking about a code that would make random numbers, so that if you told it:

RandomM(10)

it would most commonly come up with 0, and only rarely come up with ten. This could be good for the random on clicking I reckon. Thoughts?

Here's the function I've written:

Function RandomM(Range: Integer): Integer;
var
i : integer;
begin
Result := Random(Range)
for i := 0 to Result do
begin
if random(i) = 0 then Result := Result - i
if Result < 0 then Result := Result + i
end;
Result := Result + random(range-Result)/4+Random(4)
if Result > range then Result := range
end;

Yakman

2007-02-24 17:47:29

so you saying if this functions results were made into a graph, they would be largest at the 0 and smallest at 10

if thats what it does, then it already exists
the 0 is called the mean, the shape the graph makes is called a normal distributuion curve, the distance between somewhere (cant remember it all) is called the standard deveation

the function is in Math.scar and is called NormDist

m0u53m4t

2007-02-25 16:20:34

Nope, because I ran this code:

{.include SRL\SRL.scar}

Function RandomM(Range: Integer): Integer;
var
i : integer;
begin
Result := Random(Range)
for i := 0 to Result do
begin
if random(i) = 0 then Result := Result - i
if Result < 0 then Result := Result + i
end;
Result := Result + random(range-Result)/4+Random(4)
if Result > range then Result := range
end;


begin
setupsrl
activateclient
repeat
clickmouse(250+normdist(200),250+normdist(200),true)
until(random(1000)=1)
repeat
clickmouse(800+randomm(200)-randomm(200),250+randomm(200)-randomm(200),true)
until(random(1000)=1)
end.

In paint, and these were my results.


Boreas

2007-02-25 16:39:35

Ya definitely more dots in the middle. I like it. Dunno if it makes a difference with detectability though.

m0u53m4t

2007-02-25 16:46:18

Dunno. Im gunna shove it in my scripts though, as its so easy to impliment:

Function HMouse(x, y, ranx, rany: integer)
begin
Mouse(x+RandomM(ranx)-RandomM(ranx),y+RandomM(ranx)-RandomM(ranx),0,0)
end;