class CGI::Session

def create_new_id

used internally for automatically generated session ids.
a random number, and a constant string. This routine is
if possible, otherwise an SHA512 hash based upon the time,
The session id is a secure random number by SecureRandom

Create a new session id.
def create_new_id
  require 'securerandom'
  begin
    # by OpenSSL, or system provided entropy pool
    session_id = SecureRandom.hex(16)
  rescue NotImplementedError
    # never happens on modern systems
    require 'digest'
    d = Digest('SHA512').new
    now = Time::now
    d.update(now.to_s)
    d.update(String(now.usec))
    d.update(String(rand(0)))
    d.update(String($$))
    d.update('foobar')
    session_id = d.hexdigest[0, 32]
  end
  session_id
end