如何使用 Zend Rand Class

How can I use the Zend Rand Class

我想为 api 使用最好的伪随机生成器,我试图得到一个但最后我找到了 Zend Rand class... 我用

安装了这个
composer require zendframework/zend-math

它下载了一个 'vendor' 文件夹和几个子文件夹。与我要使用它的位置相比,它位于父文件夹中。

(我试过用rand-class 但是Rand.php class 是一个抽象的,我用了一段时间才知道。)

我也不知道如何使用 'use'。在示例 (https://docs.zendframework.com/zend-math/rand/) 中,我看到以下行:

use Zend\Math\Rand;

$bytes = Rand::getBytes(32);

没用。

我试过了

use Zend\Math\Rand;

$string = Rand::getString(32, 'abcdefghijklmnopqrstuvwxyz');

在常规 php 文件中。

文件夹是(带有示例名称)

public_html
    main_site
        api (where I want to use it)
        vendor (installed with composer)
            zendframework
                zend-math
                    src (where Rand.php is)

我希望得到一个随机字符串。 希望有人能告诉我怎么做。

您必须包含供应商目录自动加载文件

将其放在文件的顶部

require_once __DIR__ .'/vendor/autoload.php';

实际上,这个自动加载文件正在自动加载数学库类

之后使用

use Zend\Math\Rand;

$bytes = Rand::getBytes(32);

echo $bytes;

它会起作用...!!!