/game/util.go

http://golang-game-server.googlecode.com/ · Go · 17 lines · 12 code · 3 blank · 2 comment · 0 complexity · ca9094810cda6bb933de76bce8434e83 MD5 · raw file

  1. // Copyright (C) 2010 Alex Gontmakher (gsasha@gmail.com)
  2. // This code is licensed under GPLv3
  3. package game
  4. import (
  5. "crypto/rand"
  6. "encoding/base64"
  7. )
  8. func create_random_id(bytes int) string {
  9. random_bytes := make([]byte, bytes)
  10. random_id := make([]byte, base64.URLEncoding.EncodedLen(bytes))
  11. rand.Read(random_bytes)
  12. base64.URLEncoding.Encode(random_id, random_bytes)
  13. return string(random_id)
  14. }