Core Function BinaryRandom
From Sputnik Wiki
(Difference between revisions)
(→Example) |
(→Example) |
||
Line 52: | Line 52: | ||
my $bin = Pack("A*", "Hello world!"); | my $bin = Pack("A*", "Hello world!"); | ||
// Print it | // Print it | ||
− | say BinaryExpand($bin | + | say BinaryExpand($bin); |
// Blank line | // Blank line | ||
say; | say; | ||
// Randomize the binary | // Randomize the binary | ||
− | BinaryRandom($bin); | + | BinaryRandom($bin, RandomSeed()); |
// Print it | // Print it | ||
say BinaryExpand($bin); | say BinaryExpand($bin); |
Revision as of 22:45, 1 August 2014
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.