1 people like it.

Pseudoword generator

Pseudoword generator based on code from Evan Fosmark circa 2009.

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
let rnd = System.Random()

let vowels = "aeiou"
let consonants = set ['a'..'z'] - set vowels

let from xs = xs |> Seq.nth (rnd.Next(Seq.length xs))

let vowel () = from vowels |> string
let consonant () = from consonants |> string
let cv () = consonant() + vowel()
let cvc () = cv() + consonant()
let syllable () = (from [vowel; cv; cvc])()

let pseudoword() = String.concat "" [for x in 0..rnd.Next(1,3) -> syllable ()]

pseudoword()
val rnd : System.Random

Full name: Script.rnd
namespace System
Multiple items
type Random =
  new : unit -> Random + 1 overload
  member Next : unit -> int + 2 overloads
  member NextBytes : buffer:byte[] -> unit
  member NextDouble : unit -> float

Full name: System.Random

--------------------
System.Random() : unit
System.Random(Seed: int) : unit
val vowels : string

Full name: Script.vowels
val consonants : Set<char>

Full name: Script.consonants
val set : elements:seq<'T> -> Set<'T> (requires comparison)

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.set
val from : xs:seq<'a> -> 'a

Full name: Script.from
val xs : seq<'a>
module Seq

from Microsoft.FSharp.Collections
val nth : index:int -> source:seq<'T> -> 'T

Full name: Microsoft.FSharp.Collections.Seq.nth
System.Random.Next() : int
System.Random.Next(maxValue: int) : int
System.Random.Next(minValue: int, maxValue: int) : int
val length : source:seq<'T> -> int

Full name: Microsoft.FSharp.Collections.Seq.length
val vowel : unit -> string

Full name: Script.vowel
Multiple items
val string : value:'T -> string

Full name: Microsoft.FSharp.Core.Operators.string

--------------------
type string = System.String

Full name: Microsoft.FSharp.Core.string
val consonant : unit -> string

Full name: Script.consonant
val cv : unit -> string

Full name: Script.cv
val cvc : unit -> string

Full name: Script.cvc
val syllable : unit -> string

Full name: Script.syllable
val pseudoword : unit -> string

Full name: Script.pseudoword
module String

from Microsoft.FSharp.Core
val concat : sep:string -> strings:seq<string> -> string

Full name: Microsoft.FSharp.Core.String.concat
val x : int
Raw view New version

More information

Link:http://fssnip.net/tD
Posted:1 years ago
Author:Phillip Trelford
Tags: random