07-18-2023, 11:05 PM
Another trick that works with Ruby 1.8+ and is fast is:
>> require "openssl"
>> OpenSSL::Random.random_bytes(20).unpack('H*').join
=> "2f3ff53dd712ba2303a573d9f9a8c1dbc1942d28"
It get's you random hex string. Similar way you should be able to generate base64 string ('M*').
>> require "openssl"
>> OpenSSL::Random.random_bytes(20).unpack('H*').join
=> "2f3ff53dd712ba2303a573d9f9a8c1dbc1942d28"
It get's you random hex string. Similar way you should be able to generate base64 string ('M*').