Core Function BinaryRandom
From Sputnik Wiki
(Difference between revisions)
(→Example) |
|||
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, RandomSeed()); | ||
+ | // 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! | ||
+ | // | ||
+ | // 00 AE AC 8A CA 81 65 48 5A 7A 73 2E -- -- -- -- .®¬.Ê.eHZzs. | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:Core Function]] | [[Category:Core Function]] |
Revision as of 22:33, 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, RandomSeed()); // 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! // // 00 AE AC 8A CA 81 65 48 5A 7A 73 2E -- -- -- -- .®¬.Ê.eHZzs.