AutoHotkey Community

It is currently May 26th, 2012, 3:28 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: March 14th, 2009, 6:22 am 
Offline

Joined: May 14th, 2008, 9:48 pm
Posts: 110
Hey i was researching an idea which lead me to create this script to test a concept.

The script uses random to generate a random number, and depending on the number, it will add or subtract a set amount from a variable that started out as 0.


So far I've had it open for like 20mins, and I can't get the number to get higher than 5 or lower then -5.

Basically it only goes from -5 to 5 and inbetween.
Why is this?

Here is the script.


Code:
count=0
gui, add, text, h20 w200 vin, 0
gui, show, Ticker
settimer, check, 450
return

check:
gui, submit, nohide
count=%in%
random, ran, 1, 10
if ran=1
{
envadd, count, 1
guicontrol,,in, %count%
return
}
if ran=2
{
envsub, count, 1
guicontrol,,in, %count%
return
}
if ran=3
{
envsub, count, 5
guicontrol,,in, %count%
return
}
if ran=4
{
envadd, count, 2
guicontrol,,in, %count%
return
}
if ran=5
{
envsub, count, 2
guicontrol,,in, %count%
return
}
if ran=6
{
envadd, count, 3
guicontrol,,in, %count%
return
}
if ran=7
{
envsub, count, 3
guicontrol,,in, %count%
return
}
if ran=8
{
envadd, count, 4
guicontrol,,in, %count%
return
}
if ran=9
{
envsub, count, 4
guicontrol,,in, %count%
return
}
if ran=10
{
envadd, count, 5
guicontrol,,in, %count%
return
}
return

F12:
exitapp


[Moved from General Chat forum. ~jaco0646]
________
Colorado Medical Marijuana


Last edited by jmanx on February 10th, 2011, 9:42 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 14th, 2009, 7:03 am 
AFAIK the random generator creates equidistributed numbers.
So all your if-blocks get a 10% chance of execution.
And there is always a matching add-block for each subtract-block.
So each block reverses the impact of another block. Your number should always stay around 0.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 14th, 2009, 8:18 am 
more variation but still swinging around 0:

Code:
number := 0
min := 0
max := 0
avg := 0
R_Index := 0
positiv := 0
negativ := 0
Random, randold, 1, 10
loop
{

   Random, rand, 1, 10
   if (rand < randold)
   {
       Random, rand2, 1, 10
       number += rand2
       total += number
      R_Index ++
   }
   if (rand > randold)
   {
       Random, rand2, 1, 10
       number -= rand2
       total += number
      R_Index ++
   }
   if (number > max)
      max := number
   if (number < min)
      min := number

   if (number > 0)
      positiv ++
   if (number < 0)
      negativ ++

   avg := total // R_Index
   
      
      
   Tooltip, Number: %number%  || Avg: %avg% || Min: %min% || Max: %max% ||`n`n Iteration: %R_Index% || Larger_0: %positiv% || Smaller_0: %negativ%
   randold := rand
;   sleep 20
}


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 14th, 2009, 5:51 pm 
Offline

Joined: May 14th, 2008, 9:48 pm
Posts: 110
actually I appended it a bit and it seems to go random now.

Here's the source.

Code:
count=0
gui, add, text, h20 w200 vin, 0
gui, show, Ticker
settimer, check, 450
return

check:
random, ran, 1, 10
if ran=1
{
envadd, count, 1
guicontrol,,in, %count%
return
}
if ran=2
{
envsub, count, 1
guicontrol,,in, %count%
return
}
if ran=3
{
envsub, count, 5
guicontrol,,in, %count%
return
}
if ran=4
{
envadd, count, 2
guicontrol,,in, %count%
return
}
if ran=5
{
envsub, count, 2
guicontrol,,in, %count%
return
}
if ran=6
{
envadd, count, 3
guicontrol,,in, %count%
return
}
if ran=7
{
envsub, count, 3
guicontrol,,in, %count%
return
}
if ran=8
{
envadd, count, 4
guicontrol,,in, %count%
return
}
if ran=9
{
envsub, count, 4
guicontrol,,in, %count%
return
}
if ran=10
{
envadd, count, 5
guicontrol,,in, %count%
return
}
return

F12:
exitapp

________
MAZDA XEDOS PICTURE


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, Google [Bot], Yahoo [Bot] and 19 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group