Php 如何使用Zend Rand类

Php 如何使用Zend Rand类,php,random,zend-framework,Php,Random,Zend Framework,我想为api使用最好的伪随机生成器,我试图得到一个,但最后我找到了Zend Rand类。。。 我安装了这个 composer require zendframework/zend-math 它下载了一个“供应商”文件夹和几个子文件夹。与我想使用它的地方相比,它位于父文件夹中 我尝试使用rand类,但过了一会儿我发现rand.php类是一个抽象类 我也不知道如何使用“use”。在示例中,我看到以下几行: use Zend\Math\Rand; $bytes = Rand::getBytes(3

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

composer require zendframework/zend-math
它下载了一个“供应商”文件夹和几个子文件夹。与我想使用它的地方相比,它位于父文件夹中

我尝试使用rand类,但过了一会儿我发现rand.php类是一个抽象类

我也不知道如何使用“use”。在示例中,我看到以下几行:

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';
实际上,这个自动加载文件正在自动加载math lib的类

使用之后

use Zend\Math\Rand;

$bytes = Rand::getBytes(32);

echo $bytes;

它会起作用的

我还发现了另一种生成随机字符串的方法: