Core Function RandomSeed

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
(Created page with "<pre> RandomSeed( <flag> ) </pre> === Description === Generator a cryptographically strong random number for use as a seed. === Parameters === == flag == Optional; Type of r...")
 
m (1 revision)
 
(6 intermediate revisions by one user not shown)
Line 1: Line 1:
 
<pre>
 
<pre>
RandomSeed( <flag> )
+
RandomSeed( <flag>, <size> )
 
</pre>
 
</pre>
  
Line 9: Line 9:
 
=== Parameters ===
 
=== Parameters ===
  
== flag ==
+
==== flag ====
  
 
Optional; Type of random number to generate.
 
Optional; Type of random number to generate.
Line 16: Line 16:
 
0 = Generate a random unsigned Int32
 
0 = Generate a random unsigned Int32
 
1 = Generate a random unsigned Int64
 
1 = Generate a random unsigned Int64
 +
2 = Generate a random binary variable (you provide size)
 
</pre>
 
</pre>
  
 
Default: 0
 
Default: 0
 +
 +
==== size ====
 +
 +
Optional; Size in bytes of the binary variable to make
 +
 +
This is only when when flag is 2
 +
 +
Default: 4
  
 
=== Return Value ===  
 
=== Return Value ===  
  
Success: Returns a cryptographically strong random number.
+
Success: Returns a cryptographically strong random number/binary array.
  
 
Failure: Return null.
 
Failure: Return null.
Line 35: Line 44:
  
 
====  Example ====
 
====  Example ====
 +
 +
Generation
  
 
<syntaxhighlight lang="sputnik">
 
<syntaxhighlight lang="sputnik">
 
$random = RandomSeed(); // 32 Bit
 
$random = RandomSeed(); // 32 Bit
 
$random = RandomSeed(1); // 64 Bit
 
$random = RandomSeed(1); // 64 Bit
 +
$random = RandomSeed(2, 10); // Binary variable 10 bytes in size
 +
</syntaxhighlight>
 +
 +
Apply to seed to Sputniks internal RNG
 +
 +
<syntaxhighlight lang="sputnik">
 +
$Seed = RandomSeed();
 +
RandomSeedSet($Seed);
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
[[Category:Core Function]]
 
[[Category:Core Function]]

Latest revision as of 12:37, 14 June 2015

RandomSeed( <flag>, <size> )

Contents

Description

Generator a cryptographically strong random number for use as a seed.

Parameters

flag

Optional; Type of random number to generate.

0 = Generate a random unsigned Int32
1 = Generate a random unsigned Int64
2 = Generate a random binary variable (you provide size)

Default: 0

size

Optional; Size in bytes of the binary variable to make

This is only when when flag is 2

Default: 4

Return Value

Success: Returns a cryptographically strong random number/binary array.

Failure: Return null.

Remarks

This uses the the .NET RNGCryptoServiceProvider to do the generating.

You can use the return value for anything that needs a good seed.

This can also be used to generate random numbers but RandomVar() is more generic for that task.

Example

Generation

$random = RandomSeed(); // 32 Bit
$random = RandomSeed(1); // 64 Bit
$random = RandomSeed(2, 10); // Binary variable 10 bytes in size

Apply to seed to Sputniks internal RNG

$Seed = RandomSeed();
RandomSeedSet($Seed);
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox