Created
December 9, 2010 12:58
-
-
Save OnorioCatenacci/734687 to your computer and use it in GitHub Desktop.
Return a random string from an array of strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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