Core Function BinaryRandom

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
(Created page with "<pre> BinaryRandom( <binary-array>, <seed> ) </pre> === Description === Randomize all bytes in a binary variable. === Parameters === ==== binary-array ==== The binary varia...")
 
m (1 revision)
 
(4 intermediate revisions by one user not shown)
Line 1: Line 1:
 
<pre>
 
<pre>
BinaryRandom( <binary-array>, <seed> )
+
BinaryRandom( <binary-array>, <seed> )
 
</pre>
 
</pre>
  
Line 44: Line 44:
 
//
 
//
 
// 4E 49 E3 26 CC B5 98 BC 0A 2C 62 7A -- -- -- -- NIã&̵...,bz
 
// 4E 49 E3 26 CC B5 98 BC 0A 2C 62 7A -- -- -- -- NIã&̵...,bz
 +
</syntaxhighlight>
 +
 +
Cryptographically secure seed use
 +
 +
<syntaxhighlight lang="sputnik">
 +
// Convert a string to binary
 +
my $bin = Pack("A*", "Hello world!");
 +
// Print it
 +
say BinaryExpand($bin);
 +
// Blank line
 +
say;
 +
// Randomize the binary
 +
BinaryRandom($bin, RandomSeed());
 +
// Print it
 +
say BinaryExpand($bin);
 +
// Prints:
 +
// 48 65 6C 6C 6F 20 77 6F 72 6C 64 21 -- -- -- -- Hello world!
 +
//
 +
// 00 AE AC 8A CA 81 65 48 5A 7A 73 2E -- -- -- -- .®¬.Ê.eHZzs.
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
[[Category:Core Function]]
 
[[Category:Core Function]]

Latest revision as of 12:37, 14 June 2015

BinaryRandom( <binary-array>, <seed> )

Contents

Description

Randomize all bytes in a binary variable.

Parameters

binary-array

The binary variable to use.

seed

Optional; The seed to use when generating the random numbers

Return Value

Success: Returns true.

Failure: Returns false.

Remarks

None.

Example

// Convert a string to binary
my $bin = Pack("A*", "Hello world!");
// Print it
say BinaryExpand($bin);
// Blank line
say;
// Randomize the binary
BinaryRandom($bin);
// Print it
say BinaryExpand($bin);
// Prints:
// 48 65 6C 6C 6F 20 77 6F 72 6C 64 21 -- -- -- -- Hello world!
//
// 4E 49 E3 26 CC B5 98 BC 0A 2C 62 7A -- -- -- -- NIã&̵...,bz

Cryptographically secure seed use

// Convert a string to binary
my $bin = Pack("A*", "Hello world!");
// Print it
say BinaryExpand($bin);
// Blank line
say;
// Randomize the binary
BinaryRandom($bin, RandomSeed());
// Print it
say BinaryExpand($bin);
// Prints:
// 48 65 6C 6C 6F 20 77 6F 72 6C 64 21 -- -- -- -- Hello world!
//
// 00 AE AC 8A CA 81 65 48 5A 7A 73 2E -- -- -- -- .®¬.Ê.eHZzs.
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox