jerrygarciuh has asked for the wisdom of the Perl Monks concerning the following question:
I wanted to present the following subroutine for critique. It is cobbled together from code in Camel (2nd) and a post somewhere on PM from a long ways back. I wanted to know what folks thought of it as a random session/transaction ID generator. I need something sufficiently random that the kiddies won't be able to jack sessions by guessing the ID sequence.
Is the following sub sufficient to my aims?
TIA
jg
_____________________________________________________#!/usr/bin/perl -w use strict; my ($v,$n,$l); $v = srand( time() ^ ($$ + ($$ << 15)) ); #Camel 2nd pg 223 sub sid { #random character from a PM post, can't remember whose my @Chars = split '','abcdefghijkmnopqrstuvwxyzABCDEFGHJKMNPQRSTUV +WXYZ23456789'; for (1..($ARGV[0] ||= 1)){ for (1..7){ $l .= $Chars[rand @Chars]; } } $n = int( rand 1000000); }
|
|---|