AutoHotkey Community

It is currently May 27th, 2012, 10:44 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: February 20th, 2008, 4:33 am 
Offline

Joined: May 10th, 2007, 2:52 am
Posts: 194
Location: China/ Canada
Test
Code:
TestNum = 300000 ; TestNum
Random,, WinExist("A")
Progress = 0
Progress, B
ANum := Round(TestNum / 100)
TimeCheck := A_TickCount
NumGenerate := A_TickCount
Loop %TestNum%
{
 NumGenerate := NumGenerate_Window(NumGenerate) ; NumGenerate Check
 If NumGenerate < 0
  msgbox, error
; Random,, A_TickCount
; Random, NumGenerate, 0.000000, 1.000000
 Msg .= NumGenerate "N"
 NumCheck := Round(NumGenerate // 0.1)
 NumC_%NumCheck% += 1
 If Mod(A_Index, ANum) = 1
  Progress, % Progress += 1
 If (A_Index + 1 = TestNum)
  NumGenerateRec := NumGenerate
}
;Clipboard := Msg
TimeCheck := A_TickCount - timecheck
CheckPos := InStr(Msg, ErrorLevel := "N" NumGenerateRec "N" NumGenerate "N")
NumC_S = 0
Loop
{
 CheckPos := InStr(Msg, ErrorLevel, false, CheckPos += 1)
 If CheckPos = 0
  break
 Else
  NumC_S += 1
}
If NumC_S
 Msg := "Error"
Else
 Msg := "Done"
Msg .= A_Space " " Round(NumC_S / TestNum * 100, 1) "%`n<" TimeCheck ">`n"
Loop, 10
{
 ANum := Mod(A_Index, 10)
 Msg .= "[" Round(0.1 * ANum, 1) "*]" NumC_%ANum% "`n"
}
Progress, Off
MsgBox, 64, Number Generating Test, %Msg%`n%NumGenerate%
return
Original Version
Code:
NumGenerate(InputNum = 0, Num_S = 30000, RecLength = 1000)
{
 static x = -1, CoordRec, ColorCheck, ColorRecList = "S0xFFFFFFS0x000000S"
 global NumGenerate
 If Mod(x += 1, Num_S) = 0
 {
  If NumGenerate =
  {
   If InputNum = 0
    NumGenerate := ((A_MDay * 24 + A_Hour) * 60 + A_Min) * 60 + A_Sec
   Else
    NumGenerate := InputNum
  }
  MouseGetPos, CoordX, CoordY
  Loop
  {
   PixelGetColor, ColorCheck, %CoordX%, %CoordY%, Slow
   IfNotInString, ColorRecList, S%ColorCheck%S
   {
    If (StrLen(ColorRecList) > RecLength)
     ColorRecList := "S0xFFFFFFS0x000000S" ColorCheck "S"
    Else
     ColorRecList .= ColorCheck "S"
    CoordRec := (1 * A_ScreenWidth + CoordX) * A_ScreenHeight + CoordY
    break
   }
   If Mod(A_Index, 2) = 1
    CoordX := Mod(CoordX - Mod(A_Index, 31) + A_ScreenWidth, A_ScreenWidth)
   Else
    CoordY := Mod(CoordY - Mod(A_Index, 31) + A_ScreenHeight, A_ScreenHeight)
  }
 }
 NumGenerate := Mod(NumGenerate * A_TickCount + ColorCheck, CoordRec)
 return NumGenerate / CoordRec
}
Window Support Version
Code:
NumGenerate_Window(InputNum = 0, Num_S = 30000, RecLength = 1000)
{
 static x = -1, CoordRec, ColorCheck, ColorRecList = "S0xFFFFFFS0x000000S", WindowRecList, WindowRecListN, WindowCheck1
 global NumGenerate
 If Mod(x += 1, Num_S) = 0
 {
  A_FormatIntegerRec := A_FormatInteger
  SetFormat, INTEGER, D
  If x = 0
  {
   If NumGenerate =
   {
    If InputNum = 0
     NumGenerate := ((A_MDay * 24 + A_Hour) * 60 + A_Min) * 60 + A_Sec
    Else
     NumGenerate := InputNum
   }
   WinGet, WindowCheck, List
   Loop %WindowCheck%
   {
    WinGetTitle, WindowCheck0, % "ahk_id " WindowCheck%A_Index%
    WindowRec_S .= WindowCheck0
   }
   StringCheck := Mod(StrLen(WindowRec_S), 3 * 3)
   StringTrimRight, WindowRec_S, WindowRec_S, StringCheck
   WindowRecListN := StrLen(WindowRec_S) / 3
   Loop, Parse, WindowRec_S
   {
    ANum := Floor(Mod(A_Index, WindowRecListN)) + 1
    If StringCalc%ANum%
     StringCalc%ANum% := StringCalc%ANum% * 256 + Asc(A_LoopField)
    Else
     StringCalc%ANum% := Asc(A_LoopField)
   }
   WindowRecList = N
   Loop %WindowRecListN%
    WindowRecList .= A_Index "_" StringCalc%A_Index% "N"
   SetFormat, INTEGER, %A_FormatIntegerRec%
  }
  MouseGetPos, CoordX, CoordY
  Loop
  {
   PixelGetColor, ColorCheck, %CoordX%, %CoordY%, Slow
   IfNotInString, ColorRecList, S%ColorCheck%S
   {
    If (StrLen(ColorRecList) > RecLength)
     ColorRecList := "S0xFFFFFFS0x000000S" ColorCheck "S"
    Else
     ColorRecList .= ColorCheck "S"
    CoordRec := (1 * A_ScreenWidth + CoordX) * A_ScreenHeight + CoordY
    break
   }
   If Mod(A_Index, 2) = 1
    CoordX := Mod(CoordX - Mod(A_Index, 31) + A_ScreenWidth, A_ScreenWidth)
   Else
    CoordY := Mod(CoordY - Mod(A_Index, 31) + A_ScreenHeight, A_ScreenHeight)
  }
  RegExMatch(WindowRecList, "N" Floor(Mod(x // Num_S + 1, WindowRecListN) + 1) "_(\d+)N", WindowCheck)
 }
 NumGenerate := Mod(NumGenerate * (A_TickCount + WindowCheck1) + ColorCheck, CoordRec)
 return NumGenerate / CoordRec
}
Special Version
Code:
NumGenerate_S(InputNum = 0, Num_S = 30000)
{
 static x = -1, ColorCheck, CoordCheck, TimeCheck
 global NumGenerate
 If Mod(x += 1, Num_S) = 0
 {
  If NumGenerate =
  {
   NumGenerate := WinExist("A")
   If InputNum
    if InputNum is number
     NumGenerate := InputNum
  }
  MouseGetPos, CoordX, CoordY
  CoordCheck := (1 * A_ScreenWidth + CoordX) * A_ScreenHeight + CoordY
  PixelGetColor, ColorCheck, %CoordX%, %CoordY%, Slow
  TimeCheck := (((A_TickCount / 10 + A_MSec) * 60 + A_Sec) * 60 + A_Min) * 24 + A_Hour
 }
 NumGenerate := Mod(NumGenerate * ColorCheck + CoordCheck, TimeCheck)
 return NumGenerate / TimeCheck
}
Calculation
Code:
NumCalc(a, b, c, d)
{
 return Mod(a * b + c, d)
}
Previous Setting
Code:
CoordRec := CoordX * A_ScreenHeight + CoordY
; probably would not have good enough quality if CoordX not high enough
(in testing, CoordX would be high enough if right click on Tray icon)
Code:
; (Window Support Version)
Num_S = 30000000
; for comparison testing, but probably not good enough if in regular use

_________________
Sakurako ^_^


Last edited by Sakurako on February 22nd, 2008, 8:57 am, edited 5 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 20th, 2008, 10:13 am 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
whats the use of this? does it just give you numbers?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 20th, 2008, 10:20 am 
Offline

Joined: May 10th, 2007, 2:52 am
Posts: 194
Location: China/ Canada
It should be able to generate a number which is neither less than 0 nor greater than 1 ...

_________________
Sakurako ^_^


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 20th, 2008, 10:24 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
So does this, but what's the point?
Code:
Random, number, 0.0, 1.0
MsgBox %number%


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 20th, 2008, 10:31 am 
Offline

Joined: May 10th, 2007, 2:52 am
Posts: 194
Location: China/ Canada
Better encryption method might require generating of irregular number, but for current system theoretically it would be unlikely to have good enough irregularity. Note that even with NumGenerate() function the irregularity might still not be good enough ...

_________________
Sakurako ^_^


Last edited by Sakurako on February 20th, 2008, 10:52 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 20th, 2008, 10:52 am 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
I dont understand the point


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 20th, 2008, 11:00 am 
Offline

Joined: May 10th, 2007, 2:52 am
Posts: 194
Location: China/ Canada
Code:
TestS := Round(NumGenerate() * 300000)
Random, Test0, 0, 300000
Random,, NewSeed
Random, Test1, 0, 300000
Msgbox, 64, NumTest, NumGenerate() %TestS%`nTest0 %Test0%`nTest1 %Test1%
Reload
return

NumGenerate(Num_S = 30000, RecLength = 1000)
{
 static x = 0, CoordRec, ColorCheck, ColorRecList = "S0xFFFFFFS0x000000S"
 x += 1
 If Mod(x, Num_S) = 1
 {
  MouseGetPos, CoordX, CoordY
  Loop
  {
   PixelGetColor, ColorCheck, %CoordX%, %CoordY%, Slow
   IfNotInString, ColorRecList, S%ColorCheck%S
   {
    If (StrLen(ColorRecList) > RecLength)
     ColorRecList := "S0xFFFFFFS0x000000S" ColorCheck "S"
    Else
     ColorRecList .= ColorCheck "S"
    CoordRec := CoordX * A_ScreenHeight + CoordY
    break
   }
   If Mod(A_Index, 2) = 1
    CoordX := Mod(CoordX - Mod(A_Index, 31) + A_ScreenWidth, A_ScreenWidth)
   Else
    CoordY := Mod(CoordY - Mod(A_Index, 31) + A_ScreenHeight, A_ScreenHeight)
  }
 }
 ErrorLevel := Mod(ErrorLevel * A_TickCount + ColorCheck, CoordRec)
 return ErrorLevel / CoordRec
}

_________________
Sakurako ^_^


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 20th, 2008, 11:03 am 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
that doesnt really explain anything :?
and what would you use these "random" numbers for anyway?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 20th, 2008, 11:15 am 
Just noticed that the command should be
Code:
Random,, String
but not
Code:
Random,, Text
... But not sure for what user would use number generating ...


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 20th, 2008, 11:27 am 
Offline

Joined: February 20th, 2008, 11:20 am
Posts: 5
i don't see what's for?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 20th, 2008, 11:34 am 
Offline

Joined: May 10th, 2007, 2:52 am
Posts: 194
Location: China/ Canada
It would be up to user decision ...

_________________
Sakurako ^_^


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 20th, 2008, 7:26 pm 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
.....yes if the user wants a function for generating random numbers that is several thousand times slower and not as random.

He probably didnt know about the "Random" function before writing this. I know I've written things before only to find out there was already a commad for it.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 20th, 2008, 10:40 pm 
Offline

Joined: May 10th, 2007, 2:52 am
Posts: 194
Location: China/ Canada
... the function provided as script, but not command. However, even as script it should not be that slow

Test Result
TestNum: 300000
Decimal Fraction Format: x.xxxxxx
----------------
NumGenerate() (Window Support Version, Num_S: 30000, RecLength: 1000)
[TimeCheck: about 25771] (Error: about 0 ~ 7, depend on system status and calculation precision)
----------------
AutoHotkey number generating command (A_TickCount)
[TimeCheck: about 19000 ~ 23000] (Error: about 150 ~ 300, but might be about 100 or about 500, depend on A_TickCount and an integer between 0 and 0xFFFFFFFF)
----------------
AutoHotkey number generating command (A_YWeek)
[TimeCheck: about 23300 ~ 27300] (Error: TestNum - 2?, depend on A_YWeek and an integer between 0 and 0xFFFFFFFF)

It might be difficult to generate irregular number, but at least the irregularity could be improved. Also note that even by Sakurako, a female tester, previous NumGenerate() still not have good enough irregularity. But using similar method and better precision, probably a number generating system that is good enough could be programmed ...

P.S. Update
Code:
CoordRec := Round((WinExist("A") / 64 + CoordX) * A_ScreenHeight + CoordY)
; CoordRec := CoordX * A_ScreenHeight + CoordY

_________________
Sakurako ^_^


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 21st, 2008, 2:50 am 
Offline

Joined: May 10th, 2007, 2:52 am
Posts: 194
Location: China/ Canada
CoordRec fix version
Code:
NumGenerate(Num_S = 30000, RecLength = 1000)
{
 static x = 0, CoordRec, ColorCheck, ColorRecList = "S0xFFFFFFS0x000000S"
 x += 1
 If Mod(x, Num_S) = 1
 {
  MouseGetPos, CoordX, CoordY
  Loop
  {
   PixelGetColor, ColorCheck, %CoordX%, %CoordY%, Slow
   IfNotInString, ColorRecList, S%ColorCheck%S
   {
    If (StrLen(ColorRecList) > RecLength)
     ColorRecList := "S0xFFFFFFS0x000000S" ColorCheck "S"
    Else
     ColorRecList .= ColorCheck "S"
    CoordRec := Round((WinExist("A") / 64 + CoordX) * A_ScreenHeight + CoordY)
    break
   }
   If Mod(A_Index, 2) = 1
    CoordX := Mod(CoordX - Mod(A_Index, 31) + A_ScreenWidth, A_ScreenWidth)
   Else
    CoordY := Mod(CoordY - Mod(A_Index, 31) + A_ScreenHeight, A_ScreenHeight)
  }
 }
 ErrorLevel := Mod(ErrorLevel * A_TickCount + ColorCheck, CoordRec)
 return ErrorLevel / CoordRec
}
Code:
NumGenerate(InputNum = 0, Num_S = 30000, RecLength = 1000)
{
 static x = 0, NumGenerate, CoordRec, ColorCheck, ColorRecList = "S0xFFFFFFS0x000000S", WindowRecList, WindowRecListN, WindowCheck1
 x += 1
 If Mod(x, Num_S) = 1
 {
  A_FormatIntegerRec := A_FormatInteger
  SetFormat, INTEGER, D
  If x = 1
  {
   If InputNum = 0
    NumGenerate := ((A_MDay * 24 + A_Hour) * 60 + A_Min) * 60 + A_Sec
   Else
    NumGenerate = InputNum
   WinGet, WindowCheck, List
   Loop %WindowCheck%
   {
    WinGetTitle, WindowCheck0, % "ahk_id " WindowCheck%A_Index%
    WindowRec_S .= WindowCheck0
   }
   StringCheck := Mod(StrLen(WindowRec_S), 3 * 3)
   StringTrimRight, WindowRec_S, WindowRec_S, StringCheck
   WindowRecListN := StrLen(WindowRec_S) / 3
   Loop, Parse, WindowRec_S
   {
    ANum := Floor(Mod(A_Index, WindowRecListN)) + 1
    If StringCalc%ANum%
     StringCalc%ANum% := StringCalc%ANum% * 256 + Asc(A_LoopField)
    Else
     StringCalc%ANum% := Asc(A_LoopField)
   }
   WindowRecList = N
   Loop %WindowRecListN%
    WindowRecList .= A_Index "_" StringCalc%A_Index% "N"
   SetFormat, INTEGER, %A_FormatIntegerRec%
  }
  MouseGetPos, CoordX, CoordY
  Loop
  {
   PixelGetColor, ColorCheck, %CoordX%, %CoordY%, Slow
   IfNotInString, ColorRecList, S%ColorCheck%S
   {
    If (StrLen(ColorRecList) > RecLength)
     ColorRecList := "S0xFFFFFFS0x000000S" ColorCheck "S"
    Else
     ColorRecList .= ColorCheck "S"
    CoordRec := Round((WinExist("A") / 64 + CoordX) * A_ScreenHeight + CoordY)
    break
   }
   If Mod(A_Index, 2) = 1
    CoordX := Mod(CoordX - Mod(A_Index, 31) + A_ScreenWidth, A_ScreenWidth)
   Else
    CoordY := Mod(CoordY - Mod(A_Index, 31) + A_ScreenHeight, A_ScreenHeight)
  }
  RegExMatch(WindowRecList, "N" Floor(Mod(x // Num_S + 1, WindowRecListN) + 1) "_(\d+)N", WindowCheck)
 }
 NumGenerate := Mod(NumGenerate * (A_TickCount + WindowCheck1) + ColorCheck, CoordRec)
 return NumGenerate / CoordRec
}

_________________
Sakurako ^_^


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 21st, 2008, 6:34 am 
Offline

Joined: February 20th, 2008, 11:20 am
Posts: 5
I am interested in why we need another random generator. it seems to me that random() should be enough for our normal use.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 21 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