|
Oktatás * Programozás 1 * Szkriptnyelvek Teaching • Programming 1 (BI) Félévek Linkek * kalendárium |
Nim2 /
generate a random hashSee also std/hashes . Task: you want to generate a random hash. For instance, you want to store key/value pairs in a dictionary and you need a unique hash for the keys. Or, you want to create a temp file and you want to give it a unique name and for that you need a hash value. In a previous post we saw the epochTime() function. We'll use that. It's not a cryptographically secure method but for a simple task it should be enough. import std/strutils # strip, split, join import std/strformat # &"Hello {name}!" import std/times import std/hashes let et = epochTime() h = hash(et).abs # make it positive echo hash(et) # -4939203597474457342 ; can be negative echo h # 4939203597474457342 echo &"{h:x}" # 448b9380bccbe6fe ; converted to hex The
|
![]() Blogjaim, hobbi projektjeim * The Ubuntu Incident [ edit ] |