Revision history for KeyPgRandomize


Revision [21745]

Last edited on 2017-02-18 07:01:49 by CountingPine [Fix minor probable paste error: make Rnd keyword a link]
Additions:
- With the //[[CompilerOptlang|-lang qb]]// dialect, a function giving the same output as ##[[KeyPgRnd|Rnd]]## in QB is used. The granularity is 24 bits.
Deletions:
- With the //[[CompilerOptlang|-lang qb]]// dialect, a function giving the same output as ##**Rnd**## in QB is used. The granularity is 24 bits.


Revision [21647]

Edited on 2016-10-30 18:58:57 by fxm [Formatting]
Deletions:


Revision [21103]

Edited on 2016-03-13 09:40:26 by fxm [Formatting]
Additions:


Revision [20477]

Edited on 2016-02-10 16:07:28 by DkLwikki [Update link format]
Additions:
[[KeyPgDeclare|declare]] [[KeyPgSub|sub]] **Randomize** ( [[KeyPgByval|byval]] //seed// [[KeyPgAs|as]] [[KeyPgDouble|double]] = -1.0, [[KeyPgByval|byval]] //algorithm// [[KeyPgAs|as]] [[KeyPgLong|long]] = 0 )
A ##[[KeyPgDouble|double]]## seed value for the random number generator. If omitted, a value based on ##[[KeyPgTimer|Timer]]## will be used instead.
An integer value to select the algorithm. If omitted, the default algorithm for the current [[CompilerDialects|language dialect]] is used.
Sets the random seed that helps ##[[KeyPgRnd|Rnd]]## generate random numbers, and selects the algorithm to use. Valid values for ##//algorithm//## are:
##**0**## - Default for current [[CompilerDialects|language dialect]]. This is algorithm ##**3**## in the //[[CompilerOptlang|-lang fb]]// dialect, ##**4**## in the //[[CompilerOptlang|-lang qb]]// dialect and ##**1**## in the //[[CompilerOptlang|-lang fblite]]// dialect.
For any given seed, each algorithm will produce a specific, deterministic sequence of numbers for that seed. If you want each call to ##**Randomize**## to produce a different sequence of numbers, a seed that is not quite predictable should be used - for example, the value returned from ##[[KeyPgTimer|Timer]]##. Omitting the ##//seed//## parameter will use a value based on this.
Note: using the ##[[KeyPgTimer|Timer]]## value directly as a parameter will produce the same seed if used more than once in the same second. However, it is generally not worth calling ##**Randomize**## twice with unpredictable seeds anyway, because the second sequence will be no more random than the first. In most cases, the Mersenne twister should provide a sufficiently random sequence of numbers, without requiring reseeding between ##[[KeyPgRnd|Rnd]]## calls.
When you call ##**Randomize**## with the QB compatible algorithm, part of the old seed is retained. This means that if you call ##**Randomize**## several times with the same seed, you will **not** get the same sequence each time. To get a specific sequence in QB compatible mode, set the seed by calling ##[[KeyPgRnd|Rnd]]## with a negative parameter.
- With the //[[CompilerOptlang|-lang fb]]// dialect, a 32 bit Mersenne Twister function with a granularity of 32 bits is used.
- With the //[[CompilerOptlang|-lang qb]]// dialect, a function giving the same output as ##**Rnd**## in QB is used. The granularity is 24 bits.
- With the //[[CompilerOptlang|-lang deprecated]]// and //[[CompilerOptlang|-lang fblite]]// dialects, the function in the C runtime available in the system is used. The function has a granularity of 15 bits in ""Win32"", and 32 bits in Linux and DOS.
- QBASIC only had one algorithm (replicated in FB in algorithm number ##**4**##, and set as the default in the //[[CompilerOptlang|-lang qb]]// dialect).
- ##[[KeyPgRnd|Rnd]]##
- [[CompilerDialects|Language dialects]]
Deletions:
[[KeyPgDeclare declare]] [[KeyPgSub sub]] **Randomize** ( [[KeyPgByval byval]] //seed// [[KeyPgAs as]] [[KeyPgDouble double]] = -1.0, [[KeyPgByval byval]] //algorithm// [[KeyPgAs as]] [[KeyPgLong long]] = 0 )
A ##[[KeyPgDouble double]]## seed value for the random number generator. If omitted, a value based on ##[[KeyPgTimer Timer]]## will be used instead.
An integer value to select the algorithm. If omitted, the default algorithm for the current [[CompilerDialects language dialect]] is used.
Sets the random seed that helps ##[[KeyPgRnd Rnd]]## generate random numbers, and selects the algorithm to use. Valid values for ##//algorithm//## are:
##**0**## - Default for current [[CompilerDialects language dialect]]. This is algorithm ##**3**## in the //[[CompilerOptlang -lang fb]]// dialect, ##**4**## in the //[[CompilerOptlang -lang qb]]// dialect and ##**1**## in the //[[CompilerOptlang -lang fblite]]// dialect.
For any given seed, each algorithm will produce a specific, deterministic sequence of numbers for that seed. If you want each call to ##**Randomize**## to produce a different sequence of numbers, a seed that is not quite predictable should be used - for example, the value returned from ##[[KeyPgTimer Timer]]##. Omitting the ##//seed//## parameter will use a value based on this.
Note: using the ##[[KeyPgTimer Timer]]## value directly as a parameter will produce the same seed if used more than once in the same second. However, it is generally not worth calling ##**Randomize**## twice with unpredictable seeds anyway, because the second sequence will be no more random than the first. In most cases, the Mersenne twister should provide a sufficiently random sequence of numbers, without requiring reseeding between ##[[KeyPgRnd Rnd]]## calls.
When you call ##**Randomize**## with the QB compatible algorithm, part of the old seed is retained. This means that if you call ##**Randomize**## several times with the same seed, you will **not** get the same sequence each time. To get a specific sequence in QB compatible mode, set the seed by calling ##[[KeyPgRnd Rnd]]## with a negative parameter.
- With the //[[CompilerOptlang -lang fb]]// dialect, a 32 bit Mersenne Twister function with a granularity of 32 bits is used.
- With the //[[CompilerOptlang -lang qb]]// dialect, a function giving the same output as ##**Rnd**## in QB is used. The granularity is 24 bits.
- With the //[[CompilerOptlang -lang deprecated]]// and //[[CompilerOptlang -lang fblite]]// dialects, the function in the C runtime available in the system is used. The function has a granularity of 15 bits in ""Win32"", and 32 bits in Linux and DOS.
- QBASIC only had one algorithm (replicated in FB in algorithm number ##**4**##, and set as the default in the //[[CompilerOptlang -lang qb]]// dialect).
- ##[[KeyPgRnd Rnd]]##
- [[CompilerDialects Language dialects]]


Revision [17534]

Edited on 2015-04-01 12:36:19 by DkLwikki [integer => long]
Additions:
An integer value to select the algorithm. If omitted, the default algorithm for the current [[CompilerDialects language dialect]] is used.
Deletions:
An ##[[KeyPgInteger integer]]## value to select the algorithm used. If omitted, the default algorithm for the current [[CompilerDialects language dialect]] is used.


Revision [17533]

Edited on 2015-04-01 12:35:32 by DkLwikki [integer => long]
Additions:
[[KeyPgDeclare declare]] [[KeyPgSub sub]] **Randomize** ( [[KeyPgByval byval]] //seed// [[KeyPgAs as]] [[KeyPgDouble double]] = -1.0, [[KeyPgByval byval]] //algorithm// [[KeyPgAs as]] [[KeyPgLong long]] = 0 )
Deletions:
[[KeyPgDeclare declare]] [[KeyPgSub sub]] **Randomize** ( [[KeyPgByval byval]] //seed// [[KeyPgAs as]] [[KeyPgDouble double]] = -1.0, [[KeyPgByval byval]] //algorithm// [[KeyPgAs as]] [[KeyPgInteger integer]] = 0 )


Revision [16136]

Edited on 2012-02-24 18:38:59 by DkLwikki [New "real" Rnd() algorithm added (number 5)]
Additions:
##**5**## - Available on ""Win32"" and Linux, using system features (""Win32"" Crypto API, Linux /dev/urandom) to provide cryptographically random numbers. If those system APIs are unavailable, algorithm ##**3**## will be used instead.
Deletions:
##**5**## - Available on ""Win32"" and Linux, using system features (""Win32"" Crypto API, Linux /dev/urandom) to provide cryptographically random numbers. If those system APIs are unavailable, algorithm 3 will be used instead.


Revision [16135]

Edited on 2012-02-24 18:37:48 by DkLwikki [New "real" Rnd() algorithm added (number 5)]
Additions:
##**5**## - Available on ""Win32"" and Linux, using system features (""Win32"" Crypto API, Linux /dev/urandom) to provide cryptographically random numbers. If those system APIs are unavailable, algorithm 3 will be used instead.
Deletions:
##**5**## - Available on Win32 and Linux, using system features (Win32 Crypto API, Linux /dev/urandom) to provide cryptographically random numbers. If those system APIs are unavailable, algorithm 3 will be used instead.


Revision [16134]

Edited on 2012-02-24 18:36:56 by DkLwikki [New "real" Rnd() algorithm added (number 5)]
Additions:
##**5**## - Available on Win32 and Linux, using system features (Win32 Crypto API, Linux /dev/urandom) to provide cryptographically random numbers. If those system APIs are unavailable, algorithm 3 will be used instead.


Revision [14126]

Edited on 2009-03-14 05:10:17 by CountingPine [Try a different explanation; remove the stuff about v.21 (not really needed)]
Additions:
For any given seed, each algorithm will produce a specific, deterministic sequence of numbers for that seed. If you want each call to ##**Randomize**## to produce a different sequence of numbers, a seed that is not quite predictable should be used - for example, the value returned from ##[[KeyPgTimer Timer]]##. Omitting the ##//seed//## parameter will use a value based on this.
Note: using the ##[[KeyPgTimer Timer]]## value directly as a parameter will produce the same seed if used more than once in the same second. However, it is generally not worth calling ##**Randomize**## twice with unpredictable seeds anyway, because the second sequence will be no more random than the first. In most cases, the Mersenne twister should provide a sufficiently random sequence of numbers, without requiring reseeding between ##[[KeyPgRnd Rnd]]## calls.
Deletions:
For any given seed, each algorithm will produce a specific, deterministic sequence of numbers for that seed. If you want each call to ##**Randomize**## to produce a different sequence of numbers, a seed that is not quite predictable should be used - for example, the value returned from ##[[KeyPgTimer Timer]]##. Omitting the seed parameter will use a value based on this.
"##**Randomize** [[KeyPgTimer Timer]]##" should not be called too frequently though, because for the non-QB algorithms the integer value is used, so the seed will only change once a second, and calling ##**Randomize**## with the same seed will reset it to the same sequence each time.
Starting with version 0.21.0b of ""FreeBASIC"" - which has not been released at time of writing - omitting the first parameter will make it use a value based on the timer that changes more than once per second, allowing ##**Randomize**## to be called more frequently to return different sequences. This method will be recommended over using "##**Randomize** [[KeyPgTimer Timer]]##".


Revision [14124]

Edited on 2009-03-08 06:18:32 by CountingPine [Clarify: the new Randomize feature is not in the latest release]
Additions:
A ##[[KeyPgDouble double]]## seed value for the random number generator. If omitted, a value based on ##[[KeyPgTimer Timer]]## will be used instead.
"##**Randomize** [[KeyPgTimer Timer]]##" should not be called too frequently though, because for the non-QB algorithms the integer value is used, so the seed will only change once a second, and calling ##**Randomize**## with the same seed will reset it to the same sequence each time.
Starting with version 0.21.0b of ""FreeBASIC"" - which has not been released at time of writing - omitting the first parameter will make it use a value based on the timer that changes more than once per second, allowing ##**Randomize**## to be called more frequently to return different sequences. This method will be recommended over using "##**Randomize** [[KeyPgTimer Timer]]##".
Deletions:
A ##[[KeyPgDouble double]]## seed value for the random number generator. If omitted or set to ##-1.0##, a value based on ##[[KeyPgTimer Timer]]## will be used instead.
##**Randomize** [[KeyPgTimer Timer]]## should not be called too frequently though, because for the non-QB algorithms the integer value is used, so the seed will only change once a second, and calling ##**Randomize**## with the same seed will reset it to the same sequence each time.
In versions of ""FreeBASIC"" after v0.20.0b, omitting the first parameter or setting it to ##-1.0## will make it use a value based on the timer that changes more than once every second, so it is recommended to use this over ##[[KeyPgTimer Timer]]##.


Revision [13814]

Edited on 2008-10-26 15:31:28 by CountingPine [Some notes on seeds; platform/dialect differences; ...]
Additions:
A ##[[KeyPgDouble double]]## seed value for the random number generator. If omitted or set to ##-1.0##, a value based on ##[[KeyPgTimer Timer]]## will be used instead.
##**0**## - Default for current [[CompilerDialects language dialect]]. This is algorithm ##**3**## in the //[[CompilerOptlang -lang fb]]// dialect, ##**4**## in the //[[CompilerOptlang -lang qb]]// dialect and ##**1**## in the //[[CompilerOptlang -lang fblite]]// dialect.
##**4**## - Uses a function that is designed to give the same random number sequences as QBASIC. This should be stable across all platforms, and provides 24-bit precision, with a low degree of randomness.
For any given seed, each algorithm will produce a specific, deterministic sequence of numbers for that seed. If you want each call to ##**Randomize**## to produce a different sequence of numbers, a seed that is not quite predictable should be used - for example, the value returned from ##[[KeyPgTimer Timer]]##. Omitting the seed parameter will use a value based on this.
##**Randomize** [[KeyPgTimer Timer]]## should not be called too frequently though, because for the non-QB algorithms the integer value is used, so the seed will only change once a second, and calling ##**Randomize**## with the same seed will reset it to the same sequence each time.
In versions of ""FreeBASIC"" after v0.20.0b, omitting the first parameter or setting it to ##-1.0## will make it use a value based on the timer that changes more than once every second, so it is recommended to use this over ##[[KeyPgTimer Timer]]##.
When you call ##**Randomize**## with the QB compatible algorithm, part of the old seed is retained. This means that if you call ##**Randomize**## several times with the same seed, you will **not** get the same sequence each time. To get a specific sequence in QB compatible mode, set the seed by calling ##[[KeyPgRnd Rnd]]## with a negative parameter.
'' Seed the RNG to the method using C's rand()
randomize , 1
'' Print a sequence of random numbers
for i as integer = 1 to 10
print rnd
next
{{fbdoc item="lang"}}
The default algorithm used depends on the current dialect in use:
- With the //[[CompilerOptlang -lang fb]]// dialect, a 32 bit Mersenne Twister function with a granularity of 32 bits is used.
- With the //[[CompilerOptlang -lang qb]]// dialect, a function giving the same output as ##**Rnd**## in QB is used. The granularity is 24 bits.
- With the //[[CompilerOptlang -lang deprecated]]// and //[[CompilerOptlang -lang fblite]]// dialects, the function in the C runtime available in the system is used. The function has a granularity of 15 bits in ""Win32"", and 32 bits in Linux and DOS.
- The ##//algorithm//## parameter is new to ""FreeBASIC"".
- QBASIC only had one algorithm (replicated in FB in algorithm number ##**4**##, and set as the default in the //[[CompilerOptlang -lang qb]]// dialect).
Deletions:
A ##[[KeyPgDouble double]]## seed value for the random number generator. If omitted or set to ##-1.0##, the ##[[KeyPgTimer Timer]]## value will be used instead.
##**0**## - Default for current [[CompilerDialects language dialect]]. This is algorithm ##3## in the //[[CompilerOptlang -lang fb]]// dialect, ##4## in the //[[CompilerOptlang -lang qb]]// dialect and ##1## in the //[[CompilerOptlang -lang fblite]]// dialect.
##**4**## - Uses a QB compatible function. This should be stable across all platforms, and provides 24-bit precision, with a low degree of randomness.
For good results, using a seed that is not quite predictable should be used - for example, the value returned from ##[[KeyPgTimer Timer]]##. This should not be done too frequently though, because for the non-QB algorithms the integer value is used, so the seed will only change once a second, and calling ##**Randomize**## with the same seed will reset the sequence.
When you call ##**Randomize**## in QB compatible mode, part of the old seed is retained. This means that if you call ##**Randomize**## several times with the same seed, you will **not** get the same sequence each time. To get a specific sequence in QB compatible mode, set the seed by calling ##[[KeyPgRnd Rnd]]## with a negative parameter.
'' Seed the RNG, which is set to C's rand().
randomize timer, 1
- Second parameter new to ""FreeBASIC"".
- ##[[KeyPgTimer Timer]]##


Revision [12794]

The oldest known version of this page was created on 2008-04-01 15:45:59 by JeffMarshall [Some notes on seeds; platform/dialect differences; ...]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode