PHP 8.3.0 RC 6 available for testing

Random\Randomizer::shuffleBytes

(PHP 8 >= 8.2.0)

Random\Randomizer::shuffleBytesGet a byte-wise permutation of a string

说明

public Random\Randomizer::shuffleBytes(string $bytes): string

Returns a uniformly selected permutation of the input bytes.

Each possible permutation of the input bytes is equally likely to be returned.

参数

bytes

The string whose bytes are shuffled.

The input string will not be modified.

返回值

A permutation of the bytes of bytes.

错误/异常

示例

示例 #1 Random\Randomizer::shuffleBytes() example

<?php
$r
= new \Random\Randomizer();

// Shuffle bytes in a string:
echo "«", $r->shuffleBytes("PHP is great!"), "»\n";
?>

以上示例的输出类似于:

 
« ga rHs!PPiet»

示例 #2 Byte-wise shuffling breaks Unicode characters

<?php
$r
= new \Random\Randomizer();

$unicode = "