Pseudo-random hex character generator

Problem this snippet solves:

Not sure I remember why I was doing this, but...

Here's a simple example to generate pseudo-random hex characters. Don't use this for encryption--instead use the crypto commands.

Code :

# Generate 32 random hex characters
when RULE_INIT {

for { set i 0 } {$i < 32 } { incr i } {
append rand_hex [format {%x} [expr {int(rand()*16)}]]
}
log local0. "\$rand_hex: $rand_hex"
}
Published Mar 18, 2015
Version 1.0

Was this article helpful?

No CommentsBe the first to comment