Bhaveshpp

Professional Magento Developr - Healp eachother to grow

Magento 24: generate random string from token

18 Dec 2021 » magento2, php

patch code


    public function __construct(
        \Magento\Backend\App\Action\Context $context,
        \Magento\Framework\Math\Random $mathRandom
    ) {
        parent::__construct($context);
        
        $this->_mathRandom = $mathRandom;
        
    }

    public function generateRandomString($length)
    {
        return $this->_mathRandom->getRandomString(
            $length,
            \Magento\Framework\Math\Random::CHARS_DIGITS . \Magento\Framework\Math\Random::CHARS_LOWERS
        );
    }

Thanks.