type Suit = Club = 1 | Diamond = 2 | Spade = 3 | Heart = 4
type Rank = Two = 2 | Three = 3 | Four = 4 | Five = 5 | Six = 6 | Seven = 7 | Eight = 8 | Nine = 9 | Ten = 10 | Jack = 11 | Queen = 12 | King = 13 | Ace = 14
type Card = { Suit:Suit; Rank:Rank }
let RandomHand (size:int) =
let rndSuitIndex (rng:System.Random) = rng.Next(1, System.Enum.GetValues(typeof<Suit>).Length + 1)
let rndRankIndex (rng:System.Random) = rng.Next(1, System.Enum.GetValues(typeof<Rank>).Length + 2)
let randomCard (rng:System.Random) = {Suit=enum<Suit>((rndSuitIndex rng));Rank=enum<Rank>((rndRankIndex rng))}
let cards (rng:System.Random) = List.init<Card> size (fun index -> randomCard rng)
cards (System.Random())
As a C# programmer I'm trying to get into F#. I'm trying to create a function that returns a random list of cards. This currently works, but I'm sure this can be written MUCH shorter and cleaner.
Especially using the (rng:System.Random) 4 times feels like a stupid thing to do. Any tips?