Jump to content

[solved] Information about SRandom()


 Share

Recommended Posts

Hello Everyone

What does it mean by a SEED

Indeed upon using the Function SRandom the result of Random subsequently is always Constant

Can anyone tell me the significance of the function SRandom

Thanks in advance :)

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

Thanks Firefox for the Link

But i have already tried that link

My question is what is the Significance of the Function

because it sets the subsequent Random calls a Constant

Local $rand

$rand = Random()
ConsoleWrite($rand&@CR) ;This is Random

SRandom(0)
$rand = Random()
ConsoleWrite($rand&@CR) ;Always constant i.e. 0.548813502304256
Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

I don't see the point myself either, perhaps it's just an Artifact from the golden olden days.

SRandom(@hour / (@min + 1) + @sec) or something

I imagine AutoIt seeds internally.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

The internal seed is based on something more changing than seconds.

While 1
ConsoleWrite(Random() & @CrLf)
Sleep(0) ;JohnOne is the author, not me.
WEnd

Serously do not run that at it is

HotKeySet("{ESC}","_Exit")

Local $ScriptTimer = TimerInit()
Local $SleepTime = 0
SRandom(12)

While 1
    If TimerDiff($ScriptTimer) > 200 Then Exit ; exit after 0.2 seconds, else you will find yourself with a runaway console
    Sleep($SleepTime)
    ConsoleWrite(Random() & @LF)
WEnd

Func _Exit()
    Exit
EndFunc
Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

It's pseudorandom i.e. maths. The generator is the Mersenne Twister.

The seed is the initial start value (x). With x = 0 the outcome is always the same obviously. Same goes for any other 'hardcoded' seed, it will always produce the same sequence of numbers. When using a changing value like @MSEC or something like that as a seed, such predictable patterns are avoided.

You only need to seed once, not everytime prior to calling Random()!

[center]Spiderskank Spiderskank[/center]GetOpt Parse command line options UDF | AU3Text Program internationalization UDF | Identicon visual hash UDF

Link to comment
Share on other sites

Computer not enough powerful ? :D

lol probably not to be honest.

But I've been caught by something similar before

Even if you exit the script, the console still finishes all its writes

and it went on for about five minutes before I had to kill the process.

:)

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

You should only use SRandom() to initialize the Random() when you need to be able to produce the same sequence of numbers every time you run the script. An example of this might be for testing code where you need a random set of inputs, but need to use the same set of inputs for each test run after a code change, in order that the test conditions are the same.

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Link to comment
Share on other sites

You should only use SRandom() to initialize the Random() when you need to be able to produce the same sequence of numbers every time you run the script. An example of this might be for testing code where you need a random set of inputs, but need to use the same set of inputs for each test run after a code change, in order that the test conditions are the same.

I'd have to disagree with this as a general rule, maybe as a good idea for testing but certainly not the only reason to use it. If you're creating a random sequence and want to make sure that you can change the sequence when needed, you'd use a different seed otherwise you're going to keep getting the same sets of numbers. I came up with a latin square generator script that after a certain point you almost had to use a different seed to have it complete at all.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Independant of the programming language, SRandom or Seed or whatever it's called is mainly used to ascertain a repeatable sequence of pseudo-random numbers across runs or across computers.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Independant of the programming language, SRandom or Seed or whatever it's called is mainly used to ascertain a repeatable sequence of pseudo-random numbers across runs or across computers.

Thanks to everyone

The Topic seems to be SOLVED now

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...