This project has moved. For the latest updates, please go here.

System.Random Extension Methods

Random.CoinToss Method

A Random extension method that flip a coin toss.

Syntax

bool CoinToss(Random @this)

Parameters

@this
The @this to act on.

Examples


 // Copyright (c) 2013 Jonathan Magnan (http://zzzportal.com)
 // All rights reserved.
 // Licensed under MIT License (MIT)
 // License can be found here: https://zextensionmethods.codeplex.com/license
 
 using System;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Z;
 
 namespace ExtensionMethods.Examples
 {
     [TestClass]
     public class System_Random_CoinToss
     {
         [TestMethod]
         public void CoinToss()
         {
             // Type
             var @this = new Random();
 
             // Examples
             bool value = @this.CoinToss(); // return true or false at random.
         }
     }
 }
                

Random.OneOf Method

A Random extension method that return at random one of the value.

Syntax

T OneOf(Random @this,T[] values)

Parameters

@this
The @this to act on.
values
A variable-length parameters list containing arguments.

Type Parameters

T
Generic type parameter.

Examples


 // Copyright (c) 2013 Jonathan Magnan (http://zzzportal.com)
 // All rights reserved.
 // Licensed under MIT License (MIT)
 // License can be found here: https://zextensionmethods.codeplex.com/license
 
 using System;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Z;
 
 namespace ExtensionMethods.Examples
 {
     [TestClass]
     public class System_Random_OneOf
     {
         [TestMethod]
         public void OneOf()
         {
             // Type
             var @this = new Random();
 
             // Examples
             int value1 = @this.OneOf(1, 2, 3, 4); // return one of this value at random.
             string value2 = @this.OneOf("a", "b", "c", "d"); // return one of this value at random.
             object value3 = @this.OneOf(1, "a", DateTime.Now, new object()); // return one of this value at random.
         }
     }
 }
                

Random.OneOf Method

A Random extension method that return at random one of the value.

Syntax

T OneOf(Random @this,List<T> values)

Parameters

@this
The @this to act on.
values
A variable-length parameters list containing arguments.

Type Parameters

T
Generic type parameter.

Examples


 // Copyright (c) 2013 Jonathan Magnan (http://zzzportal.com)
 // All rights reserved.
 // Licensed under MIT License (MIT)
 // License can be found here: https://zextensionmethods.codeplex.com/license
 
 using System;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Z;
 
 namespace ExtensionMethods.Examples
 {
     [TestClass]
     public class System_Random_OneOf
     {
         [TestMethod]
         public void OneOf()
         {
             // Type
             var @this = new Random();
 
             // Examples
             int value1 = @this.OneOf(1, 2, 3, 4); // return one of this value at random.
             string value2 = @this.OneOf("a", "b", "c", "d"); // return one of this value at random.
             object value3 = @this.OneOf(1, "a", DateTime.Now, new object()); // return one of this value at random.
         }
     }
 }
                

Last edited Nov 23, 2013 at 7:55 PM by Jonathan_Magnan, version 1