Core Function BinaryRandom

From Sputnik Wiki
Jump to: navigation, search
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