1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374
|
<?xml version="1.0" encoding="utf-8"?>
<Type Name="Random" FullName="System.Random" FullNameSP="System_Random" Maintainer="ecma">
<TypeSignature Language="ILASM" Value=".class public serializable Random extends System.Object" />
<TypeSignature Language="C#" Value="public class Random" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi serializable beforefieldinit Random extends System.Object" />
<MemberOfLibrary>BCL</MemberOfLibrary>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyPublicKey>[00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 ]</AssemblyPublicKey>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ThreadingSafetyStatement>All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe.</ThreadingSafetyStatement>
<Base>
<BaseTypeName>System.Object</BaseTypeName>
</Base>
<Interfaces />
<Attributes>
<Attribute>
<AttributeName>System.Runtime.InteropServices.ComVisible(true)</AttributeName>
</Attribute>
</Attributes>
<Docs>
<remarks>
<attribution license="cc4" from="Microsoft" modified="false" />
<para>Pseudo-random numbers are chosen with equal probability from a finite set of numbers. The chosen numbers are not completely random because a definite mathematical algorithm is used to select them, but they are sufficiently random for practical purposes. The current implementation of the <see cref="T:System.Random" /> class is based on Donald E. Knuth's subtractive random number generator algorithm. For more information, see D. E. Knuth. "The Art of Computer Programming, volume 2: Seminumerical Algorithms". Addison-Wesley, Reading, MA, second edition, 1981. </para>
<para>The random number generation starts from a seed value. If the same seed is used repeatedly, the same series of numbers is generated. One way to produce different sequences is to make the seed value time-dependent, thereby producing a different series with each new instance of <see cref="T:System.Random" />. By default, the parameterless constructor of the <see cref="T:System.Random" /> class uses the system clock to generate its seed value, while its parameterized constructor can take an <see cref="T:System.Int32" /> value based on the number of ticks in the current time. However, because the clock has finite resolution, using the parameterless constructor to create different <see cref="T:System.Random" /> objects in close succession creates random number generators that produce identical sequences of random numbers. The following example illustrates that two <see cref="T:System.Random" /> objects that are instantiated in close succession generate an identical series of random numbers.</para>
<para>code reference: System.Random#1</para>
<para>This problem can be avoided by creating a single Random object rather than multiple ones.</para>
<para>To improve performance, create one <see cref="T:System.Random" /> object to generate many random numbers over time, instead of repeatedly creating a new <see cref="T:System.Random" /> objects to generate one random number.</para>
<para>To generate a cryptographically secure random number suitable for creating a random password, for example, use a class derived from <see cref="T:System.Security.Cryptography.RandomNumberGenerator" /> such as <see cref="T:System.Security.Cryptography.RNGCryptoServiceProvider" />.</para>
</remarks>
<summary>
<attribution license="cc4" from="Microsoft" modified="false" />
<para>Represents a pseudo-random number generator, a device that produces a sequence of numbers that meet certain statistical requirements for randomness.</para>
</summary>
</Docs>
<Members>
<Member MemberName=".ctor">
<MemberSignature Language="ILASM" Value="public rtspecialname specialname instance void .ctor()" />
<MemberSignature Language="C#" Value="public Random ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor() cil managed" />
<MemberType>Constructor</MemberType>
<AssemblyInfo>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue />
<Parameters />
<Docs>
<remarks>
<attribution license="cc4" from="Microsoft" modified="false" />
<para>The distribution of the generated numbers is uniform; each number is equally likely to be returned.</para>
<para>The default seed value is derived from the system clock and has finite resolution. As a result, different <see cref="T:System.Random" /> objects that are created in close succession by a call to the default constructor will have identical default seed values and, therefore, will produce identical sets of random numbers. This problem can be avoided by using a single <see cref="T:System.Random" /> object to generate all random numbers. You can also work around it by modifying the seed value returned by the system clock and then explicitly providing this new seed value to the <see cref="M:System.Random.#ctor(System.Int32)" /> constructor. For more information, see the <see cref="M:System.Random.#ctor(System.Int32)" /> constructor.</para>
</remarks>
<summary>
<attribution license="cc4" from="Microsoft" modified="false" />
<para>Initializes a new instance of the <see cref="T:System.Random" /> class, using a time-dependent default seed value.</para>
</summary>
</Docs>
<Excluded>0</Excluded>
</Member>
<Member MemberName=".ctor">
<MemberSignature Language="ILASM" Value="public rtspecialname specialname instance void .ctor(int32 Seed)" />
<MemberSignature Language="C#" Value="public Random (int Seed);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor(int32 Seed) cil managed" />
<MemberType>Constructor</MemberType>
<AssemblyInfo>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue />
<Parameters>
<Parameter Name="Seed" Type="System.Int32" />
</Parameters>
<Docs>
<example>
<para> The following example demonstrates using a
bitwise complement operation to obtain different random numbers using a time-dependent
seed value on high performance systems.</para>
<code lang="C#">using System;
class RandomTest {
public static void Main() {
Random rand1 = new Random();
Random rand2 = new Random(Environment.TickCount);
Console.WriteLine("The random number is {0}",rand1.Next());
Console.WriteLine("The random number is {0}",rand2.Next());
Random rdm1 = new Random(unchecked(Environment.TickCount));
Random rdm2 = new Random(~unchecked(Environment.TickCount));
Console.WriteLine("The random number is {0}",rdm1.Next());
Console.WriteLine("The random number is {0}",rdm2.Next());
}
}
</code>
<c>
<para>The output is </para>
<para>The random number is 1990211954</para>
<para>The random number is 1990211954</para>
<para>The random number is 1990211954</para>
<para>The random number is 964628126</para>
</c>
</example>
<remarks>
<attribution license="cc4" from="Microsoft" modified="false" />
<para>Providing an identical seed value to different <see cref="T:System.Random" /> objects causes each instance to produce identical sequences of random numbers.</para>
<para>If your application requires different random number sequences, invoke this constructor repeatedly with different seed values. One way to produce a unique seed value is to make it time-dependent. For example, derive the seed value from the system clock. However, the system clock might not have sufficient resolution to provide different invocations of this constructor with a different seed value. This results in random number generators that generate identical sequences of pseudo-random numbers, as illustrated by the first two <see cref="T:System.Random" /> objects in the following example. To prevent this, apply an algorithm to differentiate the seed value in each invocation, or call the <see cref="M:System.Threading.Thread.Sleep(System.Int32)" /> method to ensure that you provide each constructor with a different seed value. </para>
<para>code reference: System.Random.Ctor#4</para>
</remarks>
<summary>
<attribution license="cc4" from="Microsoft" modified="false" />
<para>Initializes a new instance of the <see cref="T:System.Random" /> class, using the specified seed value.</para>
</summary>
<param name="Seed">
<attribution license="cc4" from="Microsoft" modified="false" />A number used to calculate a starting value for the pseudo-random number sequence. If a negative number is specified, the absolute value of the number is used. </param>
</Docs>
<Excluded>0</Excluded>
</Member>
<Member MemberName="Next">
<MemberSignature Language="ILASM" Value=".method public hidebysig virtual int32 Next()" />
<MemberSignature Language="C#" Value="public virtual int Next ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig newslot virtual instance int32 Next() cil managed" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Int32</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<example>
<para>The following example demonstrates using the
<see langword="Next" /> method. The output generated by this example
will
vary.</para>
<code lang="C#">using System;
class RandomTest {
public static void Main() {
Random rand1 = new Random();
for (int i = 0; i<10;i++)
Console.WriteLine("The random number is {0}",rand1.Next());
}
}
</code>
<para>The output is</para>
<c>
<para> The random number is
1544196111</para>
<para> The random number is
181749919</para>
<para> The random number is
1045210087</para>
<para> The random number is
1073826097</para>
<para> The random number is
1533078806</para>
<para> The random number is
1083151645</para>
<para> The random number is
569083504</para>
<para> The random number is
1711370568</para>
<para> The random number is
578178313</para>
<para> The random number is
409444742</para>
</c>
</example>
<remarks>
<attribution license="cc4" from="Microsoft" modified="false" />
<para>
<see cref="M:System.Random.Next" /> generates a random number whose value ranges from zero to less than <see cref="F:System.Int32.MaxValue" />. To generate a random number whose value ranges from zero to some other positive number, use the <see cref="M:System.Random.Next(System.Int32)" /> method overload. To generate a random number within a different range, use the <see cref="M:System.Random.Next(System.Int32,System.Int32)" /> method overload.</para>
</remarks>
<summary>
<attribution license="cc4" from="Microsoft" modified="false" />
<para>Returns a nonnegative random integer.</para>
</summary>
<returns>
<attribution license="cc4" from="Microsoft" modified="false" />
<para>A 32-bit signed integer greater than or equal to zero and less than <see cref="F:System.Int32.MaxValue" />.</para>
</returns>
</Docs>
<Excluded>0</Excluded>
</Member>
<Member MemberName="Next">
<MemberSignature Language="ILASM" Value=".method public hidebysig virtual int32 Next(int32 maxValue)" />
<MemberSignature Language="C#" Value="public virtual int Next (int maxValue);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig newslot virtual instance int32 Next(int32 maxValue) cil managed" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Int32</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="maxValue" Type="System.Int32" />
</Parameters>
<Docs>
<remarks>
<para>
<block subset="none" type="behaviors">As described
above.</block>
</para>
<para>
<block subset="none" type="overrides">Override this method to customize
the algorithm used to generate the return value.</block>
</para>
<para>
<block subset="none" type="usage">Use this method to generate a psuedo-random number
less than the specified maximum value.</block>
</para>
</remarks>
<exception cref="T:System.ArgumentOutOfRangeException">
<paramref name="maxValue" /> is less than zero.</exception>
<summary>
<attribution license="cc4" from="Microsoft" modified="false" />
<para>Returns a nonnegative random integer that is less than the specified maximum.</para>
</summary>
<returns>
<attribution license="cc4" from="Microsoft" modified="false" />
<para>A 32-bit signed integer greater than or equal to zero, and less than <paramref name="maxValue" />; that is, the range of return values ordinarily includes zero but not <paramref name="maxValue" />. However, if <paramref name="maxValue" /> equals zero, <paramref name="maxValue" /> is returned.</para>
</returns>
<param name="maxValue">
<attribution license="cc4" from="Microsoft" modified="false" />The exclusive upper bound of the random number to be generated. <paramref name="maxValue" /> must be greater than or equal to zero. </param>
</Docs>
<Excluded>0</Excluded>
</Member>
<Member MemberName="Next">
<MemberSignature Language="ILASM" Value=".method public hidebysig virtual int32 Next(int32 minValue, int32 maxValue)" />
<MemberSignature Language="C#" Value="public virtual int Next (int minValue, int maxValue);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig newslot virtual instance int32 Next(int32 minValue, int32 maxValue) cil managed" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Int32</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="minValue" Type="System.Int32" />
<Parameter Name="maxValue" Type="System.Int32" />
</Parameters>
<Docs>
<exception cref="T:System.ArgumentOutOfRangeException">
<paramref name="minValue" /> is greater than <paramref name="maxValue" />.</exception>
<remarks>
<attribution license="cc4" from="Microsoft" modified="false" />
<para>Unlike the other overloads of the <see cref="M:System.Random.Next" /> method, which return only non-negative values, this method can return a negative random integer.</para>
</remarks>
<summary>
<attribution license="cc4" from="Microsoft" modified="false" />
<para>Returns a random integer that is within a specified range.</para>
</summary>
<returns>
<attribution license="cc4" from="Microsoft" modified="false" />
<para>A 32-bit signed integer greater than or equal to <paramref name="minValue" /> and less than <paramref name="maxValue" />; that is, the range of return values includes <paramref name="minValue" /> but not <paramref name="maxValue" />. If <paramref name="minValue" /> equals <paramref name="maxValue" />, <paramref name="minValue" /> is returned.</para>
</returns>
<param name="minValue">
<attribution license="cc4" from="Microsoft" modified="false" />The inclusive lower bound of the random number returned. </param>
<param name="maxValue">
<attribution license="cc4" from="Microsoft" modified="false" />The exclusive upper bound of the random number returned. <paramref name="maxValue" /> must be greater than or equal to <paramref name="minValue" />. </param>
</Docs>
<Excluded>0</Excluded>
</Member>
<Member MemberName="NextBytes">
<MemberSignature Language="ILASM" Value=".method public hidebysig virtual void NextBytes(class System.Byte[] buffer)" />
<MemberSignature Language="C#" Value="public virtual void NextBytes (byte[] buffer);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig newslot virtual instance void NextBytes(unsigned int8[] buffer) cil managed" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="buffer" Type="System.Byte[]" />
</Parameters>
<Docs>
<exception cref="T:System.ArgumentNullException">
<paramref name="buffer" /> is a <see langword="null" /> reference.</exception>
<remarks>
<attribution license="cc4" from="Microsoft" modified="false" />
<para>Each element of the array of bytes is set to a random number greater than or equal to zero, and less than or equal to <see cref="F:System.Byte.MaxValue" />.</para>
<para>To generate a cryptographically secured random number suitable for creating a random password, for example, use a method such as <see cref="M:System.Security.Cryptography.RNGCryptoServiceProvider.GetBytes(System.Byte[])" />.</para>
</remarks>
<summary>
<attribution license="cc4" from="Microsoft" modified="false" />
<para>Fills the elements of a specified array of bytes with random numbers.</para>
</summary>
<param name="buffer">
<attribution license="cc4" from="Microsoft" modified="false" />An array of bytes to contain random numbers. </param>
</Docs>
<Excluded>0</Excluded>
</Member>
<Member MemberName="NextDouble">
<MemberSignature Language="ILASM" Value=".method public hidebysig virtual float64 NextDouble()" />
<MemberSignature Language="C#" Value="public virtual double NextDouble ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig newslot virtual instance float64 NextDouble() cil managed" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Double</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<remarks>
<attribution license="cc4" from="Microsoft" modified="false" />
<para>This method is the public version of the protected method, <see cref="M:System.Random.Sample" />.</para>
</remarks>
<summary>
<attribution license="cc4" from="Microsoft" modified="false" />
<para>Returns a random floating-point number between 0.0 and 1.0.</para>
</summary>
<returns>
<attribution license="cc4" from="Microsoft" modified="false" />
<para>A double-precision floating point number greater than or equal to 0.0, and less than 1.0.</para>
</returns>
</Docs>
<Excluded>1</Excluded>
<ExcludedLibrary>ExtendedNumerics</ExcludedLibrary>
</Member>
<Member MemberName="Sample">
<MemberSignature Language="C#" Value="protected virtual double Sample ();" />
<MemberSignature Language="ILAsm" Value=".method familyhidebysig newslot virtual instance float64 Sample() cil managed" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Double</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<remarks>
<attribution license="cc4" from="Microsoft" modified="false" />
<para>To produce a different random distribution or a different random number generator principle, derive a class from the <see cref="T:System.Random" /> class and override the <see cref="M:System.Random.Sample" /> method.</para>
<block subset="none" type="note">
<para>The <see cref="M:System.Random.Sample" /> method is protected, which means that it is accessible only within the <see cref="T:System.Random" /> class and its derived classes. To generate a random number between 0 and 1 from a <see cref="T:System.Random" /> instance, call the <see cref="M:System.Random.NextDouble" /> method.</para>
</block>
</remarks>
<summary>
<attribution license="cc4" from="Microsoft" modified="false" />
<para>Returns a random floating-point number between 0.0 and 1.0.</para>
</summary>
<returns>
<attribution license="cc4" from="Microsoft" modified="false" />
<para>A double-precision floating point number greater than or equal to 0.0, and less than 1.0.</para>
</returns>
</Docs>
</Member>
</Members>
<TypeExcluded>0</TypeExcluded>
</Type>
|