Forum: Ruby hash generate

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
9aa1e92a0ebb17fdaad2fa39b4c52b8a?d=identicon&s=25 misiek (Guest)
on 2006-03-01 19:08
(Received via mailing list)
hi

I need to generate a hash like

np = Digest::MD5.new
np << "hello"
require 'base64'
md5_np = "{MD5}" << Base64.b64encode(np.digest) # =>
"XUFAKrxLKna5cZ2REBfFkg==\n"

but it will generate hash from 'hello' word I need generate like random
hash

how to do it ?
Bf1e672f5e54581db4e6d45b7030d286?d=identicon&s=25 Steven Lumos (Guest)
on 2006-03-02 02:47
(Received via mailing list)
misiek <michaelaugustyniak@gazeta.pl> writes:

> but it will generate hash from 'hello' word I need generate like random hash
>
> how to do it ?

[~]0% ruby -rdigest/md5 -rbase64 -e '5.times
{Base64.b64encode(Digest::MD5.digest(rand.to_s))}'
+BY/FhdFGehihHteFngcYA==
2s+T0TuN42QSHvHgPAmZ7w==
rlRXgFfVGQHj67XytaQSGA==
RnEqIK+mIxTvfuSh22ZfKw==
nM3iMmxfHuu8IyCDpUexSg==

Steve
This topic is locked and can not be replied to.