RE: [Disarmed] Re: random generator

"Petr Dyntar" <[email protected]> Tue, 4 Sep 2007 08:26:03 +0200
Newsgroups gmane.comp.windows.autoit.user
Message-ID <[email protected]>
i will paste here my simple random generator i maded 
its gui,if u press button it will generate number like
first 3signs are prefix
next 4 signs are date code
then some random leters and numbers
sorry its kinda programmed in my language,simple script,its making 12 digits serial numbers 
 
---------:>
 
 
#include "GUIConstants.au3"
Opt("GUIOnEventMode", 1)
$Gui = GUICreate( "Fan SN Genarator", 250, 100,400)
$button1 = GuictrlcreateButton("Vygeneruj SN!", 16, 60, 218, 34,)
GUICtrlSetOnEvent (-1,"generate")
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
$napis = GUICtrlCreateLabel ("Stiskni tlacitko pro generovani SN!",35,40,218,34)
$edit = GUICtrlCreateEdit ("Seriove Cislo",28,15,190,20,$LBS_DISABLENOSCROLL,)
GUISetState(@SW_SHOW)
 

Func generate ()
 call ("generator")
endfunc
 
func generator ()
 $fan = "FAN"
 $datum = @MDAY & @MON
 $nahoda = Random ( 10 ,99,1)
 $pismeno1 = Chr(Random(Asc("A"), Asc("Z"), 1))
 $pismeno2 = Chr(Random(Asc("A"), Asc("Z"), 1))
 $pismeno3 = Chr(Random(Asc("A"), Asc("Z"), 1))
 $SN = $fan & $datum & $nahoda & $pismeno1 & $pismeno2 & $pismeno3
 $data=GUICtrlSetData ($edit,$SN)
 $data2=guictrlread ($edit)
 $clip = ClipPut ($data2)
 $data=GUICtrlSetData ($napis,"Okopirovano! Ted uz jen Ctrl+V")
 return
endfunc 
 
Func CLOSEClicked()
  Exit
EndFunc
 
while 1
 Sleep (100)
   $msg = GUIGetMsg()
   If $msg = $GUI_EVENT_CLOSE Then Exitloop
Wend
 
 
 
 
 

-----Original Message-----
From: [email protected] [mailto:[email protected]]On Behalf Of valery_vi
Sent: Tuesday, September 04, 2007 7:19 AM
To: [email protected]
Subject: [Disarmed] [AutoIt] Re: random generator



> Each time the script is started, the random number generator is 
> being initialized from the clock. So any two scripts that are 
> started within the same second will generate the same pseudo-random 
> number sequence. 

Thus, you have to add one call of func sleep() before first line of
script to create different random numbers by the same script:

sleep(1003)

Valery

--- In AutoItList@yahoogro <mailto:AutoItList%40yahoogroups.com> ups.com, David Nuttall <danuttall@...> wrote:
>
> Ok, here is what is happening. I should know; I am the guy to put
the random
> number generator in AutoIt.
> 
> Each time the script is started, the random number generator is being
> initialized from the clock. So any two scripts that are started
within the
> same second will generate the same pseudo-random number sequence. A
way around
> this is to have the same script generate many numbers; each will be
different,
> or use a more precise timer to initialize the random number
generator. Check
> the docs for Random, specifically initializing/resetting the generator.
> 
> David "Nutster" Nuttall
> 
> 
> > From: Simon Jaeger 
> > To: AutoItList@yahoogro <mailto:AutoItList%40yahoogroups.com> ups.com 
> > Sent: Thursday, August 09, 2007 6:08 PM
> > Subject: [AutoIt] random generator
> > 
> > Hello,
> > 
> > I used a random number script that defined a random variable,
waited 15
> > seconds and then wrote it to a file. I had a very interesting
result when I
> > held down enter for a few seconds. Here is the code, then the results
> > 
> > code
> > #NoTrayIcon
> > $number=random(1,999999,0)
> > sleep(15000)
> > FileWrite("random.txt",$number&@crlf)
> > beep(1000,25)
> > 
> > now the results
> > <removed, but a lot of the same number showing up each time.>
> >
> > notice, a 14 digit number. What are the odds of that coming out
the same
> > way more than 20 times. I was hoping someone could explain this to
me. Are
> > the scripts interfering with each other somehow, using the same
memory space
> > or something?
> > 
> > Simon
> 
> 
> Be smarter than spam. See how smart SpamGuard is at giving
junk email the boot with the All-new Yahoo! Mail at
http://mrd.mail. <http://mrd.mail.yahoo.com/try_beta?.intl=ca> yahoo.com/try_beta?.intl=ca
>



 



[Non-text portions of this message have been removed]