Skip to content

Instantly share code, notes, and snippets.

@OnorioCatenacci
Created December 9, 2010 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OnorioCatenacci/734687 to your computer and use it in GitHub Desktop.
Save OnorioCatenacci/734687 to your computer and use it in GitHub Desktop.
Return a random string from an array of strings
// Copy/paste this into the FSI to see what it does.
open System
let a = [|"a";"b";"c";"d"|]
let randstring (arr:string[]) =
let r = new Random()
arr.[r.Next(arr.Length)]
let resultstring = randstring a;;
//And a variant: if the string is inside of the function, you need to declare
//slightly differently to get things to work correctly.
//Note the unit parameter to the function.
let randstring_i() =
let str_arr = [|"a";"b";"c";"d"|]
let r = new Random()
str_arr.[r.Next(str_arr.Length)]
let resultstring2 = randstring_i();;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment