Csharp/C Sharp by API/System/Random — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 15:11, 26 мая 2010
Random.Next()
<source lang="csharp"> using System; class CondOpApp {
[STAThread] static void Main(string[] args) { Random rand = new Random(); int a = 0, b = 0; for (int i = 0; i < 5; i++) { a = rand.Next() % 100; b = rand.Next() % 100; Console.WriteLine("a={0}, b={1}, so the winner is: {2}", a, b, a > b ? "a" : "b"); } }
}
</source>
Random.NextDouble()
<source lang="csharp"> using System; using System.Windows.Forms; using System.Drawing; public class Test {
static void Main() { Random roller = new Random(); double toHit = roller.NextDouble(); Console.WriteLine(toHit); }
}
</source>
Random.Next(range)
<source lang="csharp"> using System; public class RandomIntegers {
public static void Main( string[] args ) { Random randomNumbers = new Random(); int face; for ( int counter = 1; counter <= 20; counter++ ) { face = randomNumbers.Next( 1, 7 ); Console.Write( "{0} ", face ); if ( counter % 5 == 0 ) Console.WriteLine(); } }
}
</source>