Advertisement
Guest User

Untitled

a guest
Sep 16th, 2013
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.72 KB | None | 0 0
  1. namespace Wordy.Core.Data
  2.  
  3. open System
  4.  
  5. module IDGenerator =
  6.  
  7.     let private random = new System.Random()
  8.     let charsAllowed = [|
  9.         "a"; "b"; "c"; "d"; "e"; "f"; "g"; "h"; "j";"k"; "m"; "n"; "p"; "q"; "r"; "s"; "t"; "u"; "v"; "w"; "x"; "y";"z";
  10.         "2"; "3"; "4"; "5"; "6"; "7"; "8"; "9";
  11.         "A"; "B"; "C"; "D"; "E"; "F"; "G"; "H"; "J"; "K"; "L"; "M"; "N"; "P"; "Q"; "R"; "S"; "T"; "U"; "V"; "W"; "X"; "Y"; "Z"|]
  12.     let charBase = charsAllowed.Length
  13.  
  14.     let rec newID = function        
  15.         | length, id when String.IsNullOrEmpty(id) -> newID(length, "")        
  16.         | length, id when length < 1 -> id
  17.         | length, id -> newID(length - 1, charsAllowed.[random.Next(charBase)] + id)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement