Skip to content

Commit abf276c

Browse files
authored
sample formatting improvements (#4407)
1 parent 58bd3e2 commit abf276c

File tree

9 files changed

+238
-238
lines changed

9 files changed

+238
-238
lines changed

samples/snippets/cpp/VS_Snippets_CLR_System/system.Random.Next/CPP/next.cpp

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,68 @@
11

22
//<Snippet1>
3-
// Example of the Random::Next( ) methods.
3+
// Example of the Random::Next() methods.
44
using namespace System;
55

66
// Generate random numbers with no bounds specified.
7-
void NoBoundsRandoms( int seed )
7+
void NoBoundsRandoms(int seed)
88
{
9-
Console::WriteLine( "\nRandom object, seed = {0}, no bounds:", seed );
10-
Random^ randObj = gcnew Random( seed );
9+
Console::WriteLine("\nRandom object, seed = {0}, no bounds:", seed);
10+
Random^ randObj = gcnew Random(seed);
1111

1212
// Generate six random integers from 0 to int.MaxValue.
13-
for ( int j = 0; j < 6; j++ )
14-
Console::Write( "{0,11} ", randObj->Next() );
13+
for (int j = 0; j < 6; j++)
14+
Console::Write("{0,11} ", randObj->Next());
1515
Console::WriteLine();
1616
}
1717

1818

1919
// Generate random numbers with an upper bound specified.
20-
void UpperBoundRandoms( int seed, int upper )
20+
void UpperBoundRandoms(int seed, int upper)
2121
{
22-
Console::WriteLine( "\nRandom object, seed = {0}, upper bound = {1}:", seed, upper );
23-
Random^ randObj = gcnew Random( seed );
22+
Console::WriteLine("\nRandom object, seed = {0}, upper bound = {1}:", seed, upper);
23+
Random^ randObj = gcnew Random(seed);
2424

2525
// Generate six random integers from 0 to the upper bound.
26-
for ( int j = 0; j < 6; j++ )
27-
Console::Write( "{0,11} ", randObj->Next( upper ) );
26+
for (int j = 0; j < 6; j++)
27+
Console::Write("{0,11} ", randObj->Next(upper));
2828
Console::WriteLine();
2929
}
3030

3131

3232
// Generate random numbers with both bounds specified.
33-
void BothBoundsRandoms( int seed, int lower, int upper )
33+
void BothBoundsRandoms(int seed, int lower, int upper)
3434
{
35-
Console::WriteLine( "\nRandom object, seed = {0}, lower = {1}, upper = {2}:", seed, lower, upper );
36-
Random^ randObj = gcnew Random( seed );
35+
Console::WriteLine("\nRandom object, seed = {0}, lower = {1}, upper = {2}:", seed, lower, upper);
36+
Random^ randObj = gcnew Random(seed);
3737

3838
// Generate six random integers from the lower to
3939
// upper bounds.
40-
for ( int j = 0; j < 6; j++ )
41-
Console::Write( "{0,11} ", randObj->Next( lower, upper ) );
40+
for (int j = 0; j < 6; j++)
41+
Console::Write("{0,11} ", randObj->Next(lower, upper));
4242
Console::WriteLine();
4343
}
4444

4545
int main()
4646
{
47-
Console::WriteLine( "This example of the Random::Next( ) methods\n"
48-
"generates the following output.\n" );
49-
Console::WriteLine( "Create Random objects all with the same seed and "
47+
Console::WriteLine("This example of the Random::Next() methods\n"
48+
"generates the following output.\n");
49+
Console::WriteLine("Create Random objects all with the same seed and "
5050
"generate\nsequences of numbers with different "
5151
"bounds. Note the effect\nthat the various "
52-
"combinations of bounds have on the sequences." );
53-
NoBoundsRandoms( 234 );
54-
UpperBoundRandoms( 234, Int32::MaxValue );
55-
UpperBoundRandoms( 234, 2000000000 );
56-
UpperBoundRandoms( 234, 200000000 );
57-
BothBoundsRandoms( 234, 0, Int32::MaxValue );
58-
BothBoundsRandoms( 234, Int32::MinValue, Int32::MaxValue );
59-
BothBoundsRandoms( 234, -2000000000, 2000000000 );
60-
BothBoundsRandoms( 234, -200000000, 200000000 );
61-
BothBoundsRandoms( 234, -2000, 2000 );
52+
"combinations of bounds have on the sequences.");
53+
NoBoundsRandoms(234);
54+
UpperBoundRandoms(234, Int32::MaxValue);
55+
UpperBoundRandoms(234, 2000000000);
56+
UpperBoundRandoms(234, 200000000);
57+
BothBoundsRandoms(234, 0, Int32::MaxValue);
58+
BothBoundsRandoms(234, Int32::MinValue, Int32::MaxValue);
59+
BothBoundsRandoms(234, -2000000000, 2000000000);
60+
BothBoundsRandoms(234, -200000000, 200000000);
61+
BothBoundsRandoms(234, -2000, 2000);
6262
}
6363

6464
/*
65-
This example of the Random::Next( ) methods
65+
This example of the Random::Next() methods
6666
generates the following output.
6767
6868
Create Random objects all with the same seed and generate

samples/snippets/cpp/VS_Snippets_CLR_System/system.Random.Next/CPP/next1.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ void main()
2020
Console::WriteLine(" For a male: {0}", malePetNames[mIndex]);
2121
Console::WriteLine(" For a female: {0}", femalePetNames[fIndex]);
2222
}
23-
// The example displays the following output:
23+
// The example displays output similar to the following:
2424
// Suggested pet name of the day:
2525
// For a male: Koani
2626
// For a female: Maggie

samples/snippets/cpp/VS_Snippets_CLR_System/system.Random.Sample/cpp/sampleex.cpp

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using namespace System;
55

66
// This derived class converts the uniformly distributed random
7-
// numbers generated by base.Sample( ) to another distribution.
7+
// numbers generated by base.Sample() to another distribution.
88
public ref class RandomProportional : Random
99
{
1010
// The Sample method generates a distribution proportional to the value
@@ -31,98 +31,98 @@ int main(array<System::String ^> ^args)
3131
const int runCount = 1000000;
3232
const int distGroupCount = 10;
3333
const double intGroupSize =
34-
( (double) Int32::MaxValue + 1.0 ) / (double)distGroupCount;
34+
((double) Int32::MaxValue + 1.0) / (double)distGroupCount;
3535

3636
RandomProportional ^randObj = gcnew RandomProportional();
3737

3838
array<int>^ intCounts = gcnew array<int>(distGroupCount);
3939
array<int>^ realCounts = gcnew array<int>(distGroupCount);
4040

41-
Console::WriteLine(
41+
Console::WriteLine(
4242
"\nThe derived RandomProportional class overrides " +
4343
"the Sample method to \ngenerate random numbers " +
4444
"in the range [0.0, 1.0]. The distribution \nof " +
4545
"the numbers is proportional to their numeric values. " +
4646
"For example, \nnumbers are generated in the " +
4747
"vicinity of 0.75 with three times the \n" +
48-
"probability of those generated near 0.25." );
49-
Console::WriteLine(
50-
"\nRandom doubles generated with the NextDouble( ) " +
51-
"method:\n" );
48+
"probability of those generated near 0.25.");
49+
Console::WriteLine(
50+
"\nRandom doubles generated with the NextDouble() " +
51+
"method:\n");
5252

5353
// Generate and display [rows * cols] random doubles.
54-
for( int i = 0; i < rows; i++ )
54+
for (int i = 0; i < rows; i++)
5555
{
56-
for( int j = 0; j < cols; j++ )
57-
Console::Write( "{0,12:F8}", randObj->NextDouble( ) );
58-
Console::WriteLine( );
56+
for (int j = 0; j < cols; j++)
57+
Console::Write("{0,12:F8}", randObj->NextDouble());
58+
Console::WriteLine();
5959
}
6060

61-
Console::WriteLine(
62-
"\nRandom integers generated with the Next( ) " +
63-
"method:\n" );
61+
Console::WriteLine(
62+
"\nRandom integers generated with the Next() " +
63+
"method:\n");
6464

6565
// Generate and display [rows * cols] random integers.
66-
for( int i = 0; i < rows; i++ )
66+
for (int i = 0; i < rows; i++)
6767
{
68-
for( int j = 0; j < cols; j++ )
69-
Console::Write( "{0,12}", randObj->Next( ) );
70-
Console::WriteLine( );
68+
for (int j = 0; j < cols; j++)
69+
Console::Write("{0,12}", randObj->Next());
70+
Console::WriteLine();
7171
}
7272

73-
Console::WriteLine(
73+
Console::WriteLine(
7474
"\nTo demonstrate the proportional distribution, " +
7575
"{0:N0} random \nintegers and doubles are grouped " +
7676
"into {1} equal value ranges. This \n" +
7777
"is the count of values in each range:\n",
78-
runCount, distGroupCount );
79-
Console::WriteLine(
78+
runCount, distGroupCount);
79+
Console::WriteLine(
8080
"{0,21}{1,10}{2,20}{3,10}", "Integer Range",
81-
"Count", "Double Range", "Count" );
82-
Console::WriteLine(
81+
"Count", "Double Range", "Count");
82+
Console::WriteLine(
8383
"{0,21}{1,10}{2,20}{3,10}", "-------------",
84-
"-----", "------------", "-----" );
84+
"-----", "------------", "-----");
8585

8686
// Generate random integers and doubles, and then count
8787
// them by group.
88-
for( int i = 0; i < runCount; i++ )
88+
for (int i = 0; i < runCount; i++)
8989
{
90-
intCounts[ (int)( (double)randObj->Next( ) /
91-
intGroupSize ) ]++;
92-
realCounts[ (int)( randObj->NextDouble( ) *
93-
(double)distGroupCount ) ]++;
90+
intCounts[ (int)((double)randObj->Next() /
91+
intGroupSize) ]++;
92+
realCounts[ (int)(randObj->NextDouble() *
93+
(double)distGroupCount) ]++;
9494
}
9595

9696
// Display the count of each group.
97-
for( int i = 0; i < distGroupCount; i++ )
98-
Console::WriteLine(
97+
for (int i = 0; i < distGroupCount; i++)
98+
Console::WriteLine(
9999
"{0,10}-{1,10}{2,10:N0}{3,12:N5}-{4,7:N5}{5,10:N0}",
100-
(int)( (double)i * intGroupSize ),
101-
(int)( (double)( i + 1 ) * intGroupSize - 1.0 ),
100+
(int)((double)i * intGroupSize),
101+
(int)((double)(i + 1) * intGroupSize - 1.0),
102102
intCounts[ i ],
103-
( (double)i ) / (double)distGroupCount,
104-
( (double)( i + 1 ) ) / (double)distGroupCount,
105-
realCounts[ i ] );
103+
((double)i) / (double)distGroupCount,
104+
((double)(i + 1)) / (double)distGroupCount,
105+
realCounts[ i ]);
106106
return 0;
107107
}
108108

109109
/*
110-
This example of Random.Sample() displays the following output:
110+
This example of Random.Sample() displays output similar to the following:
111111
112112
The derived RandomProportional class overrides the Sample method to
113113
generate random numbers in the range [0.0, 1.0). The distribution
114114
of the numbers is proportional to the number values. For example,
115115
numbers are generated in the vicinity of 0.75 with three times the
116116
probability of those generated near 0.25.
117117
118-
Random doubles generated with the NextDouble( ) method:
118+
Random doubles generated with the NextDouble() method:
119119
120120
0.59455719 0.17589882 0.83134398 0.35795862 0.91467727 0.54022658
121121
0.93716947 0.54817519 0.94685080 0.93705478 0.18582318 0.71272428
122122
0.77708682 0.95386216 0.70412393 0.86099417 0.08275804 0.79108316
123123
0.71019941 0.84205103 0.41685082 0.58186880 0.89492302 0.73067715
124124
125-
Random integers generated with the Next( ) method:
125+
Random integers generated with the Next() method:
126126
127127
1570755704 1279192549 1747627711 1705700211 1372759203 1849655615
128128
2046235980 1210843924 1554274149 1307936697 1480207570 1057595022

samples/snippets/csharp/VS_Snippets_CLR_System/system.Random.Next/CS/next.cs

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,77 @@
1-
// Example of the Random.Next( ) methods.
1+
// Example of the Random.Next() methods.
22
using System;
33

44
public class RandomNextDemo
55
{
6-
static void Main( )
6+
static void Main()
77
{
88
//<Snippet1>
99
Console.WriteLine(
10-
"This example of the Random.Next( ) methods\n" +
11-
"generates the following output.\n" );
10+
"This example of the Random.Next() methods\n" +
11+
"generates the following output.\n");
1212
Console.WriteLine(
1313
"Create Random objects all with the same seed and " +
1414
"generate\nsequences of numbers with different " +
1515
"bounds. Note the effect\nthat the various " +
16-
"combinations of bounds have on the sequences." );
16+
"combinations of bounds have on the sequences.");
1717

18-
NoBoundsRandoms( 234 );
18+
NoBoundsRandoms(234);
1919

20-
UpperBoundRandoms( 234, Int32.MaxValue );
21-
UpperBoundRandoms( 234, 2000000000 );
22-
UpperBoundRandoms( 234, 200000000 );
20+
UpperBoundRandoms(234, Int32.MaxValue);
21+
UpperBoundRandoms(234, 2000000000);
22+
UpperBoundRandoms(234, 200000000);
2323

24-
BothBoundsRandoms( 234, 0, Int32.MaxValue );
25-
BothBoundsRandoms( 234, Int32.MinValue, Int32.MaxValue );
26-
BothBoundsRandoms( 234, -2000000000, 2000000000 );
27-
BothBoundsRandoms( 234, -200000000, 200000000 );
28-
BothBoundsRandoms( 234, -2000, 2000 );
24+
BothBoundsRandoms(234, 0, Int32.MaxValue);
25+
BothBoundsRandoms(234, Int32.MinValue, Int32.MaxValue);
26+
BothBoundsRandoms(234, -2000000000, 2000000000);
27+
BothBoundsRandoms(234, -200000000, 200000000);
28+
BothBoundsRandoms(234, -2000, 2000);
2929

3030
// Generate random numbers with no bounds specified.
31-
void NoBoundsRandoms( int seed )
31+
void NoBoundsRandoms(int seed)
3232
{
3333
Console.WriteLine(
34-
"\nRandom object, seed = {0}, no bounds:", seed );
35-
Random randObj = new Random( seed );
34+
"\nRandom object, seed = {0}, no bounds:", seed);
35+
Random randObj = new Random(seed);
3636

3737
// Generate six random integers from 0 to int.MaxValue.
38-
for( int j = 0; j < 6; j++ )
39-
Console.Write( "{0,11} ", randObj.Next( ) );
40-
Console.WriteLine( );
38+
for (int j = 0; j < 6; j++)
39+
Console.Write("{0,11} ", randObj.Next());
40+
Console.WriteLine();
4141
}
4242

4343
// Generate random numbers with an upper bound specified.
44-
void UpperBoundRandoms( int seed, int upper )
44+
void UpperBoundRandoms(int seed, int upper)
4545
{
4646
Console.WriteLine(
4747
"\nRandom object, seed = {0}, upper bound = {1}:",
48-
seed, upper );
49-
Random randObj = new Random( seed );
48+
seed, upper);
49+
Random randObj = new Random(seed);
5050

5151
// Generate six random integers from 0 to the upper bound.
52-
for( int j = 0; j < 6; j++ )
53-
Console.Write( "{0,11} ", randObj.Next( upper ) );
54-
Console.WriteLine( );
52+
for (int j = 0; j < 6; j++)
53+
Console.Write("{0,11} ", randObj.Next(upper));
54+
Console.WriteLine();
5555
}
5656

5757
// Generate random numbers with both bounds specified.
58-
void BothBoundsRandoms( int seed, int lower, int upper )
58+
void BothBoundsRandoms(int seed, int lower, int upper)
5959
{
6060
Console.WriteLine(
6161
"\nRandom object, seed = {0}, lower = {1}, " +
62-
"upper = {2}:", seed, lower, upper );
63-
Random randObj = new Random( seed );
62+
"upper = {2}:", seed, lower, upper);
63+
Random randObj = new Random(seed);
6464

6565
// Generate six random integers from the lower to
6666
// upper bounds.
67-
for( int j = 0; j < 6; j++ )
68-
Console.Write( "{0,11} ",
69-
randObj.Next( lower, upper) );
70-
Console.WriteLine( );
67+
for (int j = 0; j < 6; j++)
68+
Console.Write("{0,11} ",
69+
randObj.Next(lower, upper));
70+
Console.WriteLine();
7171
}
7272

7373
/*
74-
This example of the Random.Next( ) methods
74+
This example of the Random.Next() methods
7575
generates the following output.
7676
7777
Create Random objects all with the same seed and generate

samples/snippets/csharp/VS_Snippets_CLR_System/system.Random.Next/CS/next1.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static void Main()
2222
Console.WriteLine(" For a male: {0}", malePetNames[mIndex]);
2323
Console.WriteLine(" For a female: {0}", femalePetNames[fIndex]);
2424

25-
// The example displays the following output:
25+
// The example displays output similar to the following:
2626
// Suggested pet name of the day:
2727
// For a male: Koani
2828
// For a female: Maggie

0 commit comments

Comments
 (0)