Revision history for KeyPgRandomize


Revision [25935]

Last edited on 2022-04-14 02:12:23 by fxm [rename fbmath.bi to fbprng.bi]
Additions:
Unfinished structures for other random number generators are also available in the standard header "fbprng.bi".
Deletions:
Structures for other random number generators are also available in the standard header "fbprng.bi".


Revision [25932]

Edited on 2022-04-10 09:12:30 by fxm [rename fbmath.bi to fbprng.bi]
Additions:
An integer value to select the algorithm (see the standard header "fbprng.bi" for available algorithms). If omitted, the default algorithm for the current [[CompilerDialects|language dialect]] is used.
The constants for ##//algorithm//## are defined in ##fbprng.bi##. In the //[[CompilerOptlang|-lang fb]]// dialect, these constants are part of the ##FB## ##[[KeyPgNamespace|Namespace]]##.
Structures for other random number generators are also available in the standard header "fbprng.bi".
- Before fbc 1.10.0 (for fbc 1.08.0 and fbc 1.09.0), "fbprng.bi" was named "fbmath.bi".
Deletions:
An integer value to select the algorithm (see the standard header "fbmath.bi" for available algorithms). If omitted, the default algorithm for the current [[CompilerDialects|language dialect]] is used.
The constants for ##//algorithm//## are defined in ##fbmath.bi##. In the //[[CompilerOptlang|-lang fb]]// dialect, these constants are part of the ##FB## ##[[KeyPgNamespace|Namespace]]##.
Structures for other random number generators are also available in the standard header "fbmath.bi".


Revision [25561]

Edited on 2021-10-13 05:57:43 by fxm [formatted for .chm]
Additions:
##**Randomize**## is thread-safe (by using an internal mutex), but not thread specific.
Structures for other random number generators are also available in the standard header "fbmath.bi".
Deletions:
##**Randomize**## is thread-safe (by using an internal mutex), but not thread specific.
Structures for other random number generators are also available in the standard header "fbmath.bi".


Revision [25487]

Edited on 2021-10-12 02:21:09 by fxm [differences from versions previous to 1.08 transferred to the Version section]
Additions:
An integer value to select the algorithm (see the standard header "fbmath.bi" for available algorithms). If omitted, the default algorithm for the current [[CompilerDialects|language dialect]] is used.
The constants for ##//algorithm//## are defined in ##fbmath.bi##. In the //[[CompilerOptlang|-lang fb]]// dialect, these constants are part of the ##FB## ##[[KeyPgNamespace|Namespace]]##.
##**Randomize**## is thread-safe (by using an internal mutex), but not thread specific.
Structures for other random number generators are also available in the standard header "fbmath.bi".
{{fbdoc item="ver"}}
- Before fbc 1.08.0:
The standard "fbmath.bi" header for available algorithms did not exist.
##**Randomize**## was not thread-safe.
Deletions:
An integer value to select the algorithm (see below, or from fbc version >= 1.08 the standard header "fbmath.bi" for available algorithms). If omitted, the default algorithm for the current [[CompilerDialects|language dialect]] is used.
The constants for ##//algorithm//## are defined in ##fbmath.bi## (from fbc version 1.08). In the //[[CompilerOptlang|-lang fb]]// dialect, these constants are part of the ##FB## ##[[KeyPgNamespace|Namespace]]##.
**""-""** For fbc version >= 1.08, ##**Randomize**## is became thread-safe (by using an internal mutex), but not thread specific. Structures for other random number generators are also now available in the standard header "fbmath.bi".


Revision [25052]

Edited on 2021-06-03 08:32:43 by fxm [text improvement]
Additions:
Note: for all algorithms except algorithm #4, because the fractional part of the seed is clipped, the 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, or even possibly worse by inducing sequence overlapping. In most cases, the Mersenne twister should provide a sufficiently random sequence of numbers, without requiring reseeding between ##[[KeyPgRnd|Rnd]]## calls.
Deletions:
Note: for all algorithms except algorithm #4, because the fractional part of the seed is clipped, the 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, or maybe worse by inducing sequence overlapping. In most cases, the Mersenne twister should provide a sufficiently random sequence of numbers, without requiring reseeding between ##[[KeyPgRnd|Rnd]]## calls.


Revision [25051]

Edited on 2021-06-03 08:29:03 by fxm [text improvement]
Additions:
Note: for all algorithms except algorithm #4, because the fractional part of the seed is clipped, the 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, or maybe worse by inducing sequence overlapping. In most cases, the Mersenne twister should provide a sufficiently random sequence of numbers, without requiring reseeding between ##[[KeyPgRnd|Rnd]]## calls.
Deletions:
Note: for all algorithms except algorithm #4, because the fractional part of the seed is clipped, the 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.


Revision [25050]

Edited on 2021-06-03 03:20:32 by fxm [text improvement attempt]
Additions:
{{fbdoc item="filename" value="examples/manual/math/randomize.bas"}}%%(freebasic)
%%
Deletions:
{{fbdoc item="filename" value="examples/manual/math/randomize.bas"}}%%(freebasic)
%%


Revision [25049]

Edited on 2021-06-03 03:16:56 by fxm [text improvement attempt]
Additions:
Note: for all algorithms except algorithm #4, because the fractional part of the seed is clipped, the 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:
Note: for all algorithms except algorithm #4, because the fractional part of the seed is clipped, the 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. So multiple calls to ##**Randomize**## are **not** recommended in general.


Revision [25048]

Edited on 2021-06-03 02:24:38 by fxm [text improvement attempt]
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, but the fractional part is clipped for all algorithms except algorithm #4 (see below). If omitted, a value based on ##[[KeyPgTimer|Timer]]## will be used instead.
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: for all algorithms except algorithm #4, because the fractional part of the seed is clipped, the 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. So multiple calls to ##**Randomize**## are **not** recommended in general.
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.
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.
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. So multiple calls to ##**Randomize**## are **not** recommended in general.
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.
**""-""** After the ##**Randomize**## call copies the user seed argument (passed by value) into a local ##[[KeyPgDouble|double]]## variable, the result is then casted to ##[[KeyPgUlong|ulong]]## before use. So the fraction-part of the ##[[KeyPgDouble|double]]## is ignored in ##**Randomize**##.


Revision [25047]

Edited on 2021-06-02 15:36:45 by fxm [added description complement]
Additions:
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. So multiple calls to ##**Randomize**## are **not** recommended in general.
**""-""** After the ##**Randomize**## call copies the user seed argument (passed by value) into a local ##[[KeyPgDouble|double]]## variable, the result is then casted to ##[[KeyPgUlong|ulong]]## before use. So the fraction-part of the ##[[KeyPgDouble|double]]## is ignored in ##**Randomize**##.
Deletions:
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.


Revision [24726]

Edited on 2020-11-18 00:02:53 by fxm [valid data values for algorithm selection are now defined in fbmath.bi from fbc version 1.08 (numeric values are kept for transition with previous versions)]
Additions:
**""-""** For fbc version >= 1.08, ##**Randomize**## is became thread-safe (by using an internal mutex), but not thread specific. Structures for other random number generators are also now available in the standard header "fbmath.bi".
Deletions:
**""-""** For fbc version >= 1.08, ##**Randomize**## is became thread-safe (by using an internal mutex), but not thread specific. Structures for other random number generators are also available in the standard header "fbmath.bi".


Revision [24725]

Edited on 2020-11-16 23:55:43 by fxm [valid data values for algorithm selection are now defined in fbmath.bi from fbc version 1.08 (numeric values are kept for transition with previous versions)]
Additions:
**Note:**
**""-""** For fbc version >= 1.08, ##**Randomize**## is became thread-safe (by using an internal mutex), but not thread specific. Structures for other random number generators are also available in the standard header "fbmath.bi".
Deletions:
**Note:** For fbc version >= 1.08, ##**Randomize**## is became thread-safe (by using an internal mutex), but not thread specific. Structures for other random number generators are also available in the standard header "fbmath.bi".


Revision [24723]

Edited on 2020-11-16 03:42:13 by fxm [valid data values for algorithm selection are now defined in fbmath.bi from fbc version 1.08 (numeric values are kept for transition with previous versions)]
Additions:
**Note:** For fbc version >= 1.08, ##**Randomize**## is became thread-safe (by using an internal mutex), but not thread specific. Structures for other random number generators are also available in the standard header "fbmath.bi".
Deletions:
**Note:** For fbc version >= 1.08, ##**Randomize**## is became thread-safe (by using an internal mutex), but not thread specific.


Revision [24715]

Edited on 2020-11-15 09:14:43 by fxm [valid data values for algorithm selection are now defined in fbmath.bi from fbc version 1.08 (numeric values are kept for transition with previous versions)]
Additions:
An integer value to select the algorithm (see below, or from fbc version >= 1.08 the standard header "fbmath.bi" for available algorithms). If omitted, the default algorithm for the current [[CompilerDialects|language dialect]] is used.
Deletions:
An integer value to select the algorithm. If omitted, the default algorithm for the current [[CompilerDialects|language dialect]] is used.


Revision [24713]

Edited on 2020-11-15 07:20:29 by fxm [RANDOMIZE() became thread-safe (by only adding a mutex)]
Additions:
**Note:** For fbc version >= 1.08, ##**Randomize**## is became thread-safe (by using an internal mutex), but not thread specific.


Revision [24711]

Edited on 2020-11-15 01:28:31 by fxm [valid data values for algorithm selection are now defined in fbmath.bi from fbc version 1.08 (numeric values are kept for transition with previous versions)]
Additions:
Sets the random seed that helps ##[[KeyPgRnd|Rnd]]## generate random numbers, and selects the algorithm to use.
The constants for ##//algorithm//## are defined in ##fbmath.bi## (from fbc version 1.08). In the //[[CompilerOptlang|-lang fb]]// dialect, these constants are part of the ##FB## ##[[KeyPgNamespace|Namespace]]##.
Valid values for ##//algorithm//## are:
##FB_RND_AUTO (0)## - Default for current [[CompilerDialects|language dialect]]. This is algorithm ##FB_RND_MTWIST (3)## in the //[[CompilerOptlang|-lang fb]]// dialect, ##FB_RND_QB (4)## in the //[[CompilerOptlang|-lang qb]]// dialect and ##FB_RND_CRT (1)## in the //[[CompilerOptlang|-lang fblite]]// dialect.
##FB_RND_CRT (1)## - Uses the C runtime library's ##rand()## function. This will give different results depending on the platform.
##FB_RND_FAST (2)## - Uses a fast implementation. This should be stable across all platforms, and provides 32-bit granularity, reasonable degree of randomness.
##FB_RND_MTWIST (3)## - Uses the Mersenne Twister. This should be stable across all platforms, provides 32-bit granularity, and gives a high degree of randomness.
##FB_RND_QB (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.
##FB_RND_REAL (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 ##FB_RND_MTWIST (3)## will be used instead.
Deletions:
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.
##**1**## - Uses the C runtime library's ##rand()## function. This will give different results depending on the platform.
##**2**## - Uses a fast implementation. This should be stable across all platforms, and provides 32-bit granularity, reasonable degree of randomness.
##**3**## - Uses the Mersenne Twister. This should be stable across all platforms, provides 32-bit granularity, and gives a high degree of randomness.
##**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.
##**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 [21745]

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