Version 3 of Password generator

Updated 2016-04-15 15:59:33 by AMG

Should create a strong password:

variable _index [pid];

proc password {length} {
        global _index;
        variable _set {shW4UMe832TpaSylIdfzxbrNki9A7Q5PmZ0XDuYVg1KEGwLcJtjRCF6OqovBHn};
        variable _password {};

        for {set _char 1} {$_char <= $length} {incr _char} {
                incr _index [lindex [time {
                        while {$_index >= [string length $_set]} {
                                incr _index -[string length $_set];
                        }
                        
                        # Only usefull to increase entropy
                        
                        for {set _count $_index} {$_count <= [string length $_set]} {incr _count} {
                        
                                # Nothing to do

                        }
                        
                        set _password $_password[string index $_set $_index];
                }] 0]
        }

        return $_password;
}

Call password length inside the script.

AMG: My first instinct was to optimize this code since it is written in a seemingly wasteful way. However, there is a trick, a method to the madness. The time command is used as a random number generator, used to advance the index into the character set. So inefficient programming with somewhat unpredictable runtime is exactly the programmer's intent.

See Also