0

I want to use the best pseudo-random generator for a api, I tried to get one but at last I found Zend Rand class... I installed this with

composer require zendframework/zend-math

It downloaded a 'vendor' folder and several subfolders. It's in a parent folder compared to where I want to use it.

(I tried to use the rand-class but the Rand.php class is an abstract one, I found out after a while.)

I don't get how to use 'use' either. In examples (https://docs.zendframework.com/zend-math/rand/) I see the lines:

use Zend\Math\Rand;

$bytes = Rand::getBytes(32);

It doesn't work.

I have tried

use Zend\Math\Rand;

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

in a regular php file.

The folders are (with example-names)

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

I expect to get a randomized string. I hope someone can tell how to do it.

Valter Ekholm
  • 173
  • 2
  • 17

1 Answers1

1

You have to include the autoload file which is in the vendor directory

Place this at the top of your file

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

Actually, this autoload file is autoloading the classes of math lib

After that use

use Zend\Math\Rand;

$bytes = Rand::getBytes(32);

echo $bytes;

It will work...!!!

Rakesh Jakhar
  • 6,380
  • 2
  • 11
  • 20
  • Also I found another way to make random string: https://stackoverflow.com/questions/4356289/php-random-string-generator/31107425#31107425 – Valter Ekholm Apr 08 '19 at 16:20