AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Number Generating Utility
Goto page 1, 2  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Sakurako



Joined: 10 May 2007
Posts: 142

PostPosted: Wed Feb 20, 2008 4:33 am    Post subject: Number Generating Utility Reply with quote

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

_________________


Last edited by Sakurako on Fri Feb 22, 2008 8:57 am; edited 5 times in total
Back to top
View user's profile Send private message
tic



Joined: 22 Apr 2007
Posts: 1348

PostPosted: Wed Feb 20, 2008 10:13 am    Post subject: Reply with quote

whats the use of this? does it just give you numbers?
Back to top
View user's profile Send private message
Sakurako



Joined: 10 May 2007
Posts: 142

PostPosted: Wed Feb 20, 2008 10:20 am    Post subject: Reply with quote

It should be able to generate a number which is neither less than 0 nor greater than 1 ...
_________________
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 2540
Location: Australia, Qld

PostPosted: Wed Feb 20, 2008 10:24 am    Post subject: Reply with quote

So does this, but what's the point?
Code:
Random, number, 0.0, 1.0
MsgBox %number%
Back to top
View user's profile Send private message
Sakurako



Joined: 10 May 2007
Posts: 142

PostPosted: Wed Feb 20, 2008 10:31 am    Post subject: Reply with quote

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 ...
_________________


Last edited by Sakurako on Wed Feb 20, 2008 10:52 am; edited 1 time in total
Back to top
View user's profile Send private message
tic



Joined: 22 Apr 2007
Posts: 1348

PostPosted: Wed Feb 20, 2008 10:52 am    Post subject: Reply with quote

I dont understand the point
Back to top
View user's profile Send private message
Sakurako



Joined: 10 May 2007
Posts: 142

PostPosted: Wed Feb 20, 2008 11:00 am    Post subject: Reply with quote

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
}

_________________
Back to top
View user's profile Send private message
tic



Joined: 22 Apr 2007
Posts: 1348

PostPosted: Wed Feb 20, 2008 11:03 am    Post subject: Reply with quote

that doesnt really explain anything Confused
and what would you use these "random" numbers for anyway?
Back to top
View user's profile Send private message
Guest






PostPosted: Wed Feb 20, 2008 11:15 am    Post subject: Reply with quote

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 ...
Back to top
Lawrence



Joined: 20 Feb 2008
Posts: 4

PostPosted: Wed Feb 20, 2008 11:27 am    Post subject: Reply with quote

i don't see what's for?
Back to top
View user's profile Send private message
Sakurako



Joined: 10 May 2007
Posts: 142

PostPosted: Wed Feb 20, 2008 11:34 am    Post subject: Reply with quote

It would be up to user decision ...
_________________
Back to top
View user's profile Send private message
tic



Joined: 22 Apr 2007
Posts: 1348

PostPosted: Wed Feb 20, 2008 7:26 pm    Post subject: Reply with quote

.....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.
Back to top
View user's profile Send private message
Sakurako



Joined: 10 May 2007
Posts: 142

PostPosted: Wed Feb 20, 2008 10:40 pm    Post subject: Reply with quote

... 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

_________________
Back to top
View user's profile Send private message
Sakurako



Joined: 10 May 2007
Posts: 142

PostPosted: Thu Feb 21, 2008 2:50 am    Post subject: Reply with quote

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
}

_________________
Back to top
View user's profile Send private message
Lawrence



Joined: 20 Feb 2008
Posts: 4

PostPosted: Thu Feb 21, 2008 6:34 am    Post subject: Reply with quote

I am interested in why we need another random generator. it seems to me that random() should be enough for our normal use.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group