ExtensionMethod.NET Home of 841 C#, Visual Basic, F# and Javascript extension methods

Random.GetValues

Generates an infinite sequence of random numbers that fall within a given range.

Source

namespace Foo

open System

[<AutoOpen>]
module FsExtensions =

    type Random with
        /// Generates an infinite sequence of random numbers within the given range.
        member this.GetValues(minValue, maxValue) =
Seq.initInfinite (fun _ -> this.Next(minValue, maxValue))

Example

let rnd = Random()
for x in rnd.GetValues(1, 100) do
printfn "%d" x

Author: Joel Mueller

Submitted on: 29 okt 2010

Language: F#

Type: System.Random

Views: 3387