Skip to content

Commit 69eeb6e

Browse files
WilliamAntonRohmmairaw
authored andcommitted
backing out Random.xml sample Try. NET changes (#1563)
* updating for Try .NET * backing out Try .NET changes
1 parent f144a3b commit 69eeb6e

File tree

4 files changed

+145
-149
lines changed

4 files changed

+145
-149
lines changed

snippets/csharp/VS_Snippets_CLR_System/system.Random.Ctor/CS/ctor.cs

Lines changed: 77 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,52 @@
1-
// Example of the Random class constructors and Random.NextDouble( )
1+
//<Snippet1>
2+
// Example of the Random class constructors and Random.NextDouble( )
23
// method.
34
using System;
45
using System.Threading;
56

67
public class RandomObjectDemo
78
{
9+
// Generate random numbers from the specified Random object.
10+
static void RunIntNDoubleRandoms( Random randObj )
11+
{
12+
// Generate the first six random integers.
13+
for( int j = 0; j < 6; j++ )
14+
Console.Write( " {0,10} ", randObj.Next( ) );
15+
Console.WriteLine( );
16+
17+
// Generate the first six random doubles.
18+
for( int j = 0; j < 6; j++ )
19+
Console.Write( " {0:F8} ", randObj.NextDouble( ) );
20+
Console.WriteLine( );
21+
}
22+
23+
// Create a Random object with the specified seed.
24+
static void FixedSeedRandoms( int seed )
25+
{
26+
Console.WriteLine(
27+
"\nRandom numbers from a Random object with " +
28+
"seed = {0}:", seed );
29+
Random fixRand = new Random( seed );
30+
31+
RunIntNDoubleRandoms( fixRand );
32+
}
33+
34+
// Create a random object with a timer-generated seed.
35+
static void AutoSeedRandoms( )
36+
{
37+
// Wait to allow the timer to advance.
38+
Thread.Sleep( 1 );
39+
40+
Console.WriteLine(
41+
"\nRandom numbers from a Random object " +
42+
"with an auto-generated seed:" );
43+
Random autoRand = new Random( );
44+
45+
RunIntNDoubleRandoms( autoRand );
46+
}
47+
848
static void Main( )
949
{
10-
//<Snippet1>
1150
Console.WriteLine(
1251
"This example of the Random class constructors and " +
1352
"Random.NextDouble( ) \n" +
@@ -25,85 +64,45 @@ static void Main( )
2564
AutoSeedRandoms( );
2665
AutoSeedRandoms( );
2766
AutoSeedRandoms( );
28-
29-
// Generate random numbers from the specified Random object.
30-
void RunIntNDoubleRandoms( Random randObj )
31-
{
32-
// Generate the first six random integers.
33-
for( int j = 0; j < 6; j++ )
34-
Console.Write( " {0,10} ", randObj.Next( ) );
35-
Console.WriteLine( );
36-
37-
// Generate the first six random doubles.
38-
for( int j = 0; j < 6; j++ )
39-
Console.Write( " {0:F8} ", randObj.NextDouble( ) );
40-
Console.WriteLine( );
41-
}
42-
43-
// Create a Random object with the specified seed.
44-
void FixedSeedRandoms( int seed )
45-
{
46-
Console.WriteLine(
47-
"\nRandom numbers from a Random object with " +
48-
"seed = {0}:", seed );
49-
Random fixRand = new Random( seed );
50-
51-
RunIntNDoubleRandoms( fixRand );
52-
}
53-
54-
// Create a random object with a timer-generated seed.
55-
void AutoSeedRandoms( )
56-
{
57-
// Wait to allow the timer to advance.
58-
System.Threading.Thread.Sleep( 1 );
59-
60-
Console.WriteLine(
61-
"\nRandom numbers from a Random object " +
62-
"with an auto-generated seed:" );
63-
Random autoRand = new Random( );
64-
65-
RunIntNDoubleRandoms( autoRand );
66-
}
67-
68-
/*
69-
This example of the Random class constructors and Random.NextDouble( )
70-
generates the following output.
71-
72-
Create Random objects, and then generate and display six integers and
73-
six doubles from each.
74-
75-
Random numbers from a Random object with seed = 123:
76-
2114319875 1949518561 1596751841 1742987178 1586516133 103755708
77-
0.01700087 0.14935942 0.19470390 0.63008947 0.90976122 0.49519146
78-
79-
Random numbers from a Random object with seed = 123:
80-
2114319875 1949518561 1596751841 1742987178 1586516133 103755708
81-
0.01700087 0.14935942 0.19470390 0.63008947 0.90976122 0.49519146
82-
83-
Random numbers from a Random object with seed = 456:
84-
2044805024 1323311594 1087799997 1907260840 179380355 120870348
85-
0.21988117 0.21026556 0.39236514 0.42420498 0.24102703 0.47310170
86-
87-
Random numbers from a Random object with seed = 456:
88-
2044805024 1323311594 1087799997 1907260840 179380355 120870348
89-
0.21988117 0.21026556 0.39236514 0.42420498 0.24102703 0.47310170
90-
91-
Random numbers from a Random object with an auto-generated seed:
92-
380213349 127379247 1969091178 1983029819 1963098450 1648433124
93-
0.08824121 0.41249688 0.36445811 0.05637512 0.62702451 0.49595560
94-
95-
Random numbers from a Random object with an auto-generated seed:
96-
861793304 2133528783 1947358439 124230908 921262645 1087892791
97-
0.56880819 0.42934091 0.60162512 0.74388610 0.99432979 0.30310005
98-
99-
Random numbers from a Random object with an auto-generated seed:
100-
1343373259 1992194672 1925625700 412915644 2026910487 527352458
101-
0.04937517 0.44618494 0.83879212 0.43139707 0.36163507 0.11024451
102-
*/
103-
//</Snippet1>
10467
}
10568
}
10669

70+
/*
71+
This example of the Random class constructors and Random.NextDouble( )
72+
generates the following output.
73+
74+
Create Random objects, and then generate and display six integers and
75+
six doubles from each.
76+
77+
Random numbers from a Random object with seed = 123:
78+
2114319875 1949518561 1596751841 1742987178 1586516133 103755708
79+
0.01700087 0.14935942 0.19470390 0.63008947 0.90976122 0.49519146
80+
81+
Random numbers from a Random object with seed = 123:
82+
2114319875 1949518561 1596751841 1742987178 1586516133 103755708
83+
0.01700087 0.14935942 0.19470390 0.63008947 0.90976122 0.49519146
84+
85+
Random numbers from a Random object with seed = 456:
86+
2044805024 1323311594 1087799997 1907260840 179380355 120870348
87+
0.21988117 0.21026556 0.39236514 0.42420498 0.24102703 0.47310170
88+
89+
Random numbers from a Random object with seed = 456:
90+
2044805024 1323311594 1087799997 1907260840 179380355 120870348
91+
0.21988117 0.21026556 0.39236514 0.42420498 0.24102703 0.47310170
92+
93+
Random numbers from a Random object with an auto-generated seed:
94+
380213349 127379247 1969091178 1983029819 1963098450 1648433124
95+
0.08824121 0.41249688 0.36445811 0.05637512 0.62702451 0.49595560
96+
97+
Random numbers from a Random object with an auto-generated seed:
98+
861793304 2133528783 1947358439 124230908 921262645 1087892791
99+
0.56880819 0.42934091 0.60162512 0.74388610 0.99432979 0.30310005
100+
101+
Random numbers from a Random object with an auto-generated seed:
102+
1343373259 1992194672 1925625700 412915644 2026910487 527352458
103+
0.04937517 0.44618494 0.83879212 0.43139707 0.36163507 0.11024451
104+
*/
105+
//</Snippet1>
107106

108107
// Code added to show how to initialize Random objects with the
109108
// same timer value that will produce unique random number sequences.
Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,34 @@
1-
using System;
1+
// <Snippet2>
2+
using System;
23
using System.Threading;
34

45
public class RandomNumbers
56
{
67
public static void Main()
78
{
8-
// <Snippet2>
99
Random rand1 = new Random();
1010
Random rand2 = new Random();
11-
System.Threading.Thread.Sleep(2000);
11+
Thread.Sleep(2000);
1212
Random rand3 = new Random();
1313
ShowRandomNumbers(rand1);
1414
ShowRandomNumbers(rand2);
1515
ShowRandomNumbers(rand3);
16+
}
1617

17-
void ShowRandomNumbers(Random rand)
18-
{
19-
Console.WriteLine();
20-
byte[] values = new byte[5];
21-
rand.NextBytes(values);
22-
foreach (byte value in values)
23-
Console.Write("{0, 5}", value);
24-
Console.WriteLine();
25-
}
26-
27-
// The example displays the following output to the console:
28-
// 28 35 133 224 58
29-
//
30-
// 28 35 133 224 58
31-
//
32-
// 32 222 43 251 49
33-
// </Snippet2>
18+
private static void ShowRandomNumbers(Random rand)
19+
{
20+
Console.WriteLine();
21+
byte[] values = new byte[5];
22+
rand.NextBytes(values);
23+
foreach (byte value in values)
24+
Console.Write("{0, 5}", value);
25+
Console.WriteLine();
3426
}
3527
}
28+
// The example displays the following output to the console:
29+
// 28 35 133 224 58
30+
//
31+
// 28 35 133 224 58
32+
//
33+
// 32 222 43 251 49
34+
// </Snippet2>
Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,35 @@
1-
using System;
1+
// <Snippet4>
2+
using System;
23
using System.Threading;
34

45
public class Example
56
{
67
public static void Main()
78
{
8-
// <Snippet4>
99
Random rand1 = new Random((int) DateTime.Now.Ticks & 0x0000FFFF);
1010
Random rand2 = new Random((int) DateTime.Now.Ticks & 0x0000FFFF);
11-
System.Threading.Thread.Sleep(20);
11+
Thread.Sleep(20);
1212
Random rand3 = new Random((int) DateTime.Now.Ticks & 0x0000FFFF);
1313
ShowRandomNumbers(rand1);
1414
ShowRandomNumbers(rand2);
1515
ShowRandomNumbers(rand3);
16+
}
1617

17-
void ShowRandomNumbers(Random rand)
18-
{
19-
Console.WriteLine();
20-
byte[] values = new byte[4];
21-
rand.NextBytes(values);
22-
foreach (var value in values)
23-
Console.Write("{0, 5}", value);
24-
25-
Console.WriteLine();
26-
}
18+
private static void ShowRandomNumbers(Random rand)
19+
{
20+
Console.WriteLine();
21+
byte[] values = new byte[4];
22+
rand.NextBytes(values);
23+
foreach (var value in values)
24+
Console.Write("{0, 5}", value);
2725

28-
// The example displays output similar to the following:
29-
// 145 214 177 134 173
30-
//
31-
// 145 214 177 134 173
32-
//
33-
// 126 185 175 249 157
34-
// </Snippet4>
26+
Console.WriteLine();
3527
}
3628
}
29+
// The example displays output similar to the following:
30+
// 145 214 177 134 173
31+
//
32+
// 145 214 177 134 173
33+
//
34+
// 126 185 175 249 157
35+
// </Snippet4>
Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
using System;
1+
// <Snippet13>
2+
using System;
23
using System.Threading;
34

45
public class Example
56
{
67
public static void Main()
78
{
8-
// <Snippet13>
99
Console.WriteLine("Instantiating two random number generators...");
1010
Random rnd1 = new Random();
11-
System.Threading.Thread.Sleep(2000);
11+
Thread.Sleep(2000);
1212
Random rnd2 = new Random();
1313

1414
Console.WriteLine("\nThe first random number generator:");
@@ -18,34 +18,33 @@ public static void Main()
1818
Console.WriteLine("\nThe second random number generator:");
1919
for (int ctr = 1; ctr <= 10; ctr++)
2020
Console.WriteLine(" {0}", rnd2.Next());
21-
22-
// The example displays output like the following:
23-
// Instantiating two random number generators...
24-
//
25-
// The first random number generator:
26-
// 643164361
27-
// 1606571630
28-
// 1725607587
29-
// 2138048432
30-
// 496874898
31-
// 1969147632
32-
// 2034533749
33-
// 1840964542
34-
// 412380298
35-
// 47518930
36-
//
37-
// The second random number generator:
38-
// 1251659083
39-
// 1514185439
40-
// 1465798544
41-
// 517841554
42-
// 1821920222
43-
// 195154223
44-
// 1538948391
45-
// 1548375095
46-
// 546062716
47-
// 897797880
48-
// </Snippet13>
4921
}
5022
}
23+
// The example displays output like the following:
24+
// Instantiating two random number generators...
25+
//
26+
// The first random number generator:
27+
// 643164361
28+
// 1606571630
29+
// 1725607587
30+
// 2138048432
31+
// 496874898
32+
// 1969147632
33+
// 2034533749
34+
// 1840964542
35+
// 412380298
36+
// 47518930
37+
//
38+
// The second random number generator:
39+
// 1251659083
40+
// 1514185439
41+
// 1465798544
42+
// 517841554
43+
// 1821920222
44+
// 195154223
45+
// 1538948391
46+
// 1548375095
47+
// 546062716
48+
// 897797880
49+
// </Snippet13>
5150

0 commit comments

Comments
 (0)