-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathRandom.xml
More file actions
1690 lines (1542 loc) · 111 KB
/
Copy pathRandom.xml
File metadata and controls
1690 lines (1542 loc) · 111 KB
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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<Type Name="Random" FullName="System.Random">
<TypeSignature Language="C#" Value="public class Random" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi beforefieldinit Random extends System.Object" />
<TypeSignature Language="DocId" Value="T:System.Random" />
<TypeSignature Language="VB.NET" Value="Public Class Random" />
<TypeSignature Language="F#" Value="type Random = class" />
<TypeSignature Language="C++ CLI" Value="public ref class Random" />
<AssemblyInfo>
<AssemblyName>System.Runtime.Extensions</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.2.2.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
<AssemblyVersion>11.0.0.0</AssemblyVersion>
</AssemblyInfo>
<TypeForwardingChain>
<TypeForwarding From="netstandard" FromVersion="2.1.0.0" To="System.Runtime" ToVersion="10.0.0.0" FrameworkAlternate="net-10.0" />
<TypeForwarding From="System.Runtime.Extensions" FromVersion="10.0.0.0" To="System.Runtime" ToVersion="10.0.0.0" FrameworkAlternate="net-10.0" />
<TypeForwarding From="netstandard" FromVersion="2.1.0.0" To="System.Runtime" ToVersion="11.0.0.0" FrameworkAlternate="net-11.0" />
<TypeForwarding From="System.Runtime.Extensions" FromVersion="11.0.0.0" To="System.Runtime" ToVersion="11.0.0.0" FrameworkAlternate="net-11.0" />
<TypeForwarding From="netstandard" FromVersion="2.1.0.0" To="System.Runtime" ToVersion="5.0.0.0" FrameworkAlternate="net-5.0" />
<TypeForwarding From="System.Runtime.Extensions" FromVersion="5.0.0.0" To="System.Runtime" ToVersion="5.0.0.0" FrameworkAlternate="net-5.0" />
<TypeForwarding From="netstandard" FromVersion="2.1.0.0" To="System.Runtime" ToVersion="6.0.0.0" FrameworkAlternate="net-6.0" />
<TypeForwarding From="System.Runtime.Extensions" FromVersion="6.0.0.0" To="System.Runtime" ToVersion="6.0.0.0" FrameworkAlternate="net-6.0" />
<TypeForwarding From="netstandard" FromVersion="2.1.0.0" To="System.Runtime" ToVersion="7.0.0.0" FrameworkAlternate="net-7.0" />
<TypeForwarding From="System.Runtime.Extensions" FromVersion="7.0.0.0" To="System.Runtime" ToVersion="7.0.0.0" FrameworkAlternate="net-7.0" />
<TypeForwarding From="netstandard" FromVersion="2.1.0.0" To="System.Runtime" ToVersion="8.0.0.0" FrameworkAlternate="net-8.0" />
<TypeForwarding From="System.Runtime.Extensions" FromVersion="8.0.0.0" To="System.Runtime" ToVersion="8.0.0.0" FrameworkAlternate="net-8.0" />
<TypeForwarding From="netstandard" FromVersion="2.1.0.0" To="System.Runtime" ToVersion="9.0.0.0" FrameworkAlternate="net-9.0" />
<TypeForwarding From="System.Runtime.Extensions" FromVersion="9.0.0.0" To="System.Runtime" ToVersion="9.0.0.0" FrameworkAlternate="net-9.0" />
</TypeForwardingChain>
<Base>
<BaseTypeName>System.Object</BaseTypeName>
</Base>
<Interfaces />
<Attributes>
<Attribute FrameworkAlternate="net-10.0;net-11.0;net-8.0;net-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.Nullable(0)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.Nullable(0)>]</AttributeName>
</Attribute>
</Attributes>
<Docs>
<summary>Represents a pseudo-random number generator, which is an algorithm that produces a sequence of numbers that meet certain statistical requirements for randomness.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
> [!NOTE]
> To generate a cryptographically secure random number, such as one that's suitable for creating a random password, use one of the static methods in the <xref:System.Security.Cryptography.RandomNumberGenerator> class.
The <xref:System.Random> class represents a pseudo-random number generator, which is an algorithm that produces a sequence of numbers that meet certain statistical requirements for randomness.
Pseudo-random numbers are chosen with equal probability from a finite set of numbers. The chosen numbers are not completely random because a mathematical algorithm is used to select them, but they are sufficiently random for practical purposes. The implementation of the <xref:System.Random> class is based on a modified version of 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, third edition, 1997.
To generate a cryptographically secure random number, such as one that's suitable for creating a random password, use one of the static methods in the <xref:System.Security.Cryptography.RandomNumberGenerator?displayProperty=nameWithType> class.
## Instantiate the random number generator
You instantiate the random number generator by providing a seed value (a starting value for the pseudo-random number generation algorithm) to a <xref:System.Random.%23ctor*> class constructor. You can supply the seed value either explicitly or implicitly:
- The <xref:System.Random.%23ctor(System.Int32)> constructor uses an explicit seed value that you supply.
- The <xref:System.Random.%23ctor> constructor uses the default seed value. This is the most common way of instantiating the random number generator.
The default seed value is produced by the thread-static, pseudo-random number generator.
If the same seed is used for separate <xref:System.Random> objects, they will generate the same series of random numbers. This can be useful for creating a test suite that processes random values, or for replaying games that derive their data from random numbers.
To produce different sequences of random numbers, you can make the seed value time-dependent, thereby producing a different series with each new instance of <xref:System.Random>. The parameterized <xref:System.Random.%23ctor(System.Int32)> constructor can take an <xref:System.Int32> value based on the number of ticks in the current time, whereas the parameterless <xref:System.Random.%23ctor> constructor uses the system clock to generate its seed value.
## Thread safety
Instead of instantiating individual <xref:System.Random> objects, we recommend that you create a single <xref:System.Random> instance to generate all the random numbers needed by your app. However, <xref:System.Random> objects are not thread safe. If your app calls <xref:System.Random> methods from multiple threads, you must use a synchronization object to ensure that only one thread can access the random number generator at a time. If you don't ensure that the <xref:System.Random> object is accessed in a thread-safe way, calls to methods that return random numbers return 0.
The following example uses the C# [lock Statement](/dotnet/csharp/language-reference/keywords/lock-statement), the F# [lock function](https://fsharp.github.io/fsharp-core-docs/reference/fsharp-core-operators.html#lock) and the Visual Basic [SyncLock statement](/dotnet/visual-basic/language-reference/statements/synclock-statement) to ensure that a single random number generator is accessed by 11 threads in a thread-safe manner. Each thread generates 2 million random numbers, counts the number of random numbers generated and calculates their sum, and then updates the totals for all threads when it finishes executing.
:::code language="csharp" source="~/snippets/csharp/System/Random/Overview/threadsafeex1.cs" id="Snippet3":::
:::code language="fsharp" source="~/snippets/fsharp/System/Random/Overview/threadsafeex1.fs" id="Snippet3":::
:::code language="vb" source="~/snippets/visualbasic/System/Random/Overview/threadsafeex1.vb" id="Snippet3":::
The example ensures thread-safety in the following ways:
- The <xref:System.ThreadStaticAttribute> attribute is used to define thread-local variables that track the total number of random numbers generated and their sum for each thread.
- A lock (the `lock` statement in C#, the `lock` function in F# and the `SyncLock` statement in Visual Basic) protects access to the variables for the total count and sum of all random numbers generated on all threads.
- A semaphore (the <xref:System.Threading.CountdownEvent> object) is used to ensure that the main thread blocks until all other threads complete execution.
- The example checks whether the random number generator has become corrupted by determining whether two consecutive calls to random number generation methods return 0. If corruption is detected, the example uses the <xref:System.Threading.CancellationTokenSource> object to signal that all threads should be canceled.
- Before generating each random number, each thread checks the state of the <xref:System.Threading.CancellationToken> object. If cancellation is requested, the example calls the <xref:System.Threading.CancellationToken.ThrowIfCancellationRequested*?displayProperty=nameWithType> method to cancel the thread.
The following example is identical to the first, except that it uses a <xref:System.Threading.Tasks.Task> object and a lambda expression instead of <xref:System.Threading.Thread> objects.
:::code language="csharp" source="~/snippets/csharp/System/Random/Overview/threadsafeex2.cs" id="Snippet4":::
:::code language="fsharp" source="~/snippets/fsharp/System/Random/Overview/threadsafeex2.fs" id="Snippet4":::
:::code language="vb" source="~/snippets/visualbasic/System/Random/Overview/threadsafeex2.vb" id="Snippet4":::
It differs from the first example in the following ways:
- The variables to keep track of the number of random numbers generated and their sum in each task are local to the task, so there is no need to use the <xref:System.ThreadStaticAttribute> attribute.
- The static <xref:System.Threading.Tasks.Task.WaitAll*?displayProperty=nameWithType> method is used to ensure that the main thread doesn't complete before all tasks have finished. There is no need for the <xref:System.Threading.CountdownEvent> object.
- The exception that results from task cancellation is surfaced in the <xref:System.Threading.Tasks.Task.WaitAll*?displayProperty=nameWithType> method. In the previous example, it is handled by each thread.
## Generate different types of random numbers
The random number generator provides methods that let you generate the following kinds of random numbers:
- A series of <xref:System.Byte> values. You determine the number of byte values by passing an array initialized to the number of elements you want the method to return to the <xref:System.Random.NextBytes*> method. The following example generates 20 bytes.
:::code language="csharp" source="~/snippets/csharp/System/Random/Overview/nextbytes1.cs" id="Snippet5":::
:::code language="fsharp" source="~/snippets/fsharp/System/Random/Overview/nextbytes1.fs" id="Snippet5":::
:::code language="vb" source="~/snippets/visualbasic/System/Random/Overview/nextbytes1.vb" id="Snippet5":::
- A single integer. You can choose whether you want an integer from 0 to a maximum value (<xref:System.Int32.MaxValue?displayProperty=nameWithType> - 1) by calling the <xref:System.Random.Next> method, an integer between 0 and a specific value by calling the <xref:System.Random.Next(System.Int32)> method, or an integer within a range of values by calling the <xref:System.Random.Next(System.Int32,System.Int32)> method. In the parameterized overloads, the specified maximum value is exclusive; that is, the actual maximum number generated is one less than the specified value.
The following example calls the <xref:System.Random.Next(System.Int32,System.Int32)> method to generate 10 random numbers between -10 and 10. Note that the second argument to the method specifies the exclusive upper bound of the range of random values returned by the method. In other words, the largest integer that the method can return is one less than this value.
:::code language="csharp" source="~/snippets/csharp/System/Random/Overview/nextex1.cs" id="Snippet6":::
:::code language="fsharp" source="~/snippets/fsharp/System/Random/Overview/nextex1.fs" id="Snippet6":::
:::code language="vb" source="~/snippets/visualbasic/System/Random/Overview/nextex1.vb" id="Snippet6":::
- A single floating-point value from 0.0 to less than 1.0 by calling the <xref:System.Random.NextDouble*> method. The exclusive upper bound of the random number returned by the method is 1, so its actual upper bound is 0.99999999999999978. The following example generates 10 random floating-point numbers.
:::code language="csharp" source="~/snippets/csharp/System/Random/Overview/nextdoubleex1.cs" id="Snippet7":::
:::code language="fsharp" source="~/snippets/fsharp/System/Random/Overview/nextdoubleex1.fs" id="Snippet7":::
:::code language="vb" source="~/snippets/visualbasic/System/Random/Overview/nextdoubleex1.vb" id="Snippet7":::
> [!IMPORTANT]
> The <xref:System.Random.Next(System.Int32,System.Int32)> method allows you to specify the range of the returned random number. However, the `maxValue` parameter, which specifies the upper range returned number, is an exclusive, not an inclusive, value. This means that the method call `Next(0, 100)` returns a value between 0 and 99, and not between 0 and 100.
You can also use the <xref:System.Random> class for such tasks as generating [random Boolean values](#generate-random-boolean-values), generating [random floating-point values in a specified range](#retrieve-floating-point-values-in-a-specified-range), generating [Generate random 64-bit integers](#generate-random-64-bit-integers), and [retrieving a unique element from an array or collection](#retrieve-a-unique-element-from-an-array-or-collection).
## Substitute your own algorithm
You can implement your own random number generator by inheriting from the <xref:System.Random> class and supplying your random number generation algorithm. To supply your own algorithm, you must override the <xref:System.Random.Sample*> method, which implements the random number generation algorithm. You should also override the <xref:System.Random.Next>, <xref:System.Random.Next(System.Int32,System.Int32)>, and <xref:System.Random.NextBytes*> methods to ensure that they call your overridden <xref:System.Random.Sample*> method. You don't have to override the <xref:System.Random.Next(System.Int32)> and <xref:System.Random.NextDouble*> methods.
For an example that derives from the <xref:System.Random> class and modifies its default pseudo-random number generator, see the <xref:System.Random.Sample*> reference page.
## Retrieve the same sequence of random values
Sometimes you want to generate the same sequence of random numbers in software test scenarios and in game playing. Testing with the same sequence of random numbers allows you to detect regressions and confirm bug fixes. Using the same sequence of random number in games allows you to replay previous games.
You can generate the same sequence of random numbers by providing the same seed value to the <xref:System.Random.%23ctor(System.Int32)> constructor. The seed value provides a starting value for the pseudo-random number generation algorithm. The following example uses 100100 as an arbitrary seed value to instantiate the <xref:System.Random> object, displays 20 random floating-point values, and persists the seed value. It then restores the seed value, instantiates a new random number generator, and displays the same 20 random floating-point values. Note that the example may produce different sequences of random numbers if run on different versions of .NET.
:::code language="csharp" source="~/snippets/csharp/System/Random/Overview/same1.cs" id="Snippet12":::
:::code language="fsharp" source="~/snippets/fsharp/System/Random/Overview/same1.fs" id="Snippet12":::
:::code language="vb" source="~/snippets/visualbasic/System/Random/Overview/same1.vb" id="Snippet12":::
## Retrieve unique sequences of random numbers
Providing different seed values to instances of the <xref:System.Random> class causes each random number generator to produce a different sequence of values. You can provide a seed value either explicitly by calling the <xref:System.Random.%23ctor(System.Int32)> constructor, or implicitly by calling the <xref:System.Random.%23ctor> constructor. Most developers call the parameterless constructor, which uses the system clock. The following example uses this approach to instantiate two <xref:System.Random> instances. Each instance displays a series of 10 random integers.
:::code language="csharp" source="~/snippets/csharp/System/Random/Overview/unique.cs" id="Snippet13":::
:::code language="fsharp" source="~/snippets/fsharp/System/Random/Overview/unique.fs" id="Snippet13":::
:::code language="vb" source="~/snippets/visualbasic/System/Random/Overview/unique.vb" id="Snippet13":::
## Retrieve integers in a specified range
You can retrieve integers in a specified range by calling the <xref:System.Random.Next(System.Int32,System.Int32)> method, which lets you specify both the lower and the upper bound of the numbers you'd like the random number generator to return. The upper bound is an exclusive, not an inclusive, value. That is, it isn't included in the range of values returned by the method. The following example uses this method to generate random integers between -10 and 10. Note that it specifies 11, which is one greater than the desired value, as the value of the `maxValue` argument in the method call.
:::code language="csharp" source="~/snippets/csharp/System/Random/Overview/range1.cs" id="Snippet15":::
:::code language="fsharp" source="~/snippets/fsharp/System/Random/Overview/range1.fs" id="Snippet15":::
:::code language="vb" source="~/snippets/visualbasic/System/Random/Overview/range1.vb" id="Snippet15":::
## Retrieve integers with a specified number of digits
You can call the <xref:System.Random.Next(System.Int32,System.Int32)> method to retrieve numbers with a specified number of digits. For example, to retrieve numbers with four digits (that is, numbers that range from 1000 to 9999), you call the <xref:System.Random.Next(System.Int32,System.Int32)> method with a `minValue` value of 1000 and a `maxValue` value of 10000, as the following example shows.
:::code language="csharp" source="~/snippets/csharp/System/Random/Overview/range2.cs" id="Snippet16":::
:::code language="fsharp" source="~/snippets/fsharp/System/Random/Overview/range2.fs" id="Snippet16":::
:::code language="vb" source="~/snippets/visualbasic/System/Random/Overview/range2.vb" id="Snippet16":::
## Retrieve floating-point values in a specified range
The <xref:System.Random.NextDouble*> method returns random floating-point values that range from 0 to less than 1. However, you'll often want to generate random values in some other range.
If the interval between the minimum and maximum desired values is 1, you can add the difference between the desired starting interval and 0 to the number returned by the <xref:System.Random.NextDouble*> method. The following example does this to generate 10 random numbers between -1 and 0.
:::code language="csharp" source="~/snippets/csharp/System/Random/Overview/doublerange2.cs" id="Snippet17":::
:::code language="fsharp" source="~/snippets/fsharp/System/Random/Overview/doublerange2.fs" id="Snippet17":::
:::code language="vb" source="~/snippets/visualbasic/System/Random/Overview/doublerange2.vb" id="Snippet17":::
To generate random floating-point numbers whose lower bound is 0 but upper bound is greater than 1 (or, in the case of negative numbers, whose lower bound is less than -1 and upper bound is 0), multiply the random number by the non-zero bound. The following example does this to generate 20 million random floating-point numbers that range from 0 to <xref:System.Int64.MaxValue?displayProperty=nameWithType>. In also displays the distribution of the random values generated by the method.
:::code language="csharp" source="~/snippets/csharp/System/Random/Overview/doublerange1.cs" id="Snippet18":::
:::code language="fsharp" source="~/snippets/fsharp/System/Random/Overview/doublerange1.fs" id="Snippet18":::
:::code language="vb" source="~/snippets/visualbasic/System/Random/Overview/doublerange1.vb" id="Snippet18":::
To generate random floating-point numbers between two arbitrary values, like the <xref:System.Random.Next(System.Int32,System.Int32)> method does for integers, use the following formula:
```csharp
Random.NextDouble() * (maxValue - minValue) + minValue
```
The following example generates 1 million random numbers that range from 10.0 to 11.0, and displays their distribution.
:::code language="csharp" source="~/snippets/csharp/System/Random/Overview/doublerange3.cs" id="Snippet19":::
:::code language="fsharp" source="~/snippets/fsharp/System/Random/Overview/doublerange3.fs" id="Snippet19":::
:::code language="vb" source="~/snippets/visualbasic/System/Random/Overview/doublerange3.vb" id="Snippet19":::
## Generate random Boolean values
The <xref:System.Random> class doesn't provide methods that generate <xref:System.Boolean> values. However, you can define your own class or method to do that. The following example defines a class, `BooleanGenerator`, with a single method, `NextBoolean`. The `BooleanGenerator` class stores a <xref:System.Random> object as a private variable. The `NextBoolean` method calls the <xref:System.Random.Next(System.Int32,System.Int32)?displayProperty=nameWithType> method and passes the result to the <xref:System.Convert.ToBoolean(System.Int32)?displayProperty=nameWithType> method. Note that 2 is used as the argument to specify the upper bound of the random number. Since this is an exclusive value, the method call returns either 0 or 1.
:::code language="csharp" source="~/snippets/csharp/System/Random/Overview/booleans1.cs" id="Snippet8":::
:::code language="fsharp" source="~/snippets/fsharp/System/Random/Overview/booleans1.fs" id="Snippet8":::
:::code language="vb" source="~/snippets/visualbasic/System/Random/Overview/booleans1.vb" id="Snippet8":::
Instead of creating a separate class to generate random <xref:System.Boolean> values, the example could simply have defined a single method. In that case, however, the <xref:System.Random> object should have been defined as a class-level variable to avoid instantiating a new <xref:System.Random> instance in each method call. In Visual Basic, the Random instance can be defined as a [Static](/dotnet/visual-basic/language-reference/modifiers/static) variable in the `NextBoolean` method. The following example provides an implementation.
:::code language="csharp" source="~/snippets/csharp/System/Random/Overview/booleans2.cs" id="Snippet20":::
:::code language="fsharp" source="~/snippets/fsharp/System/Random/Overview/booleans2.fs" id="Snippet20":::
:::code language="vb" source="~/snippets/visualbasic/System/Random/Overview/booleans2.vb" id="Snippet20":::
## Generate random 64-bit integers
The overloads of the <xref:System.Random.Next*> method return 32-bit integers. However, in some cases, you might want to work with 64-bit integers. You can do this as follows:
1. Call the <xref:System.Random.NextDouble*> method to retrieve a double-precision floating point value.
2. Multiply that value by <xref:System.Int64.MaxValue?displayProperty=nameWithType>.
The following example uses this technique to generate 20 million random long integers and categorizes them in 10 equal groups. It then evaluates the distribution of the random numbers by counting the number in each group from 0 to <xref:System.Int64.MaxValue?displayProperty=nameWithType>. As the output from the example shows, the numbers are distributed more or less equally through the range of a long integer.
:::code language="csharp" source="~/snippets/csharp/System/Random/Overview/long1.cs" id="Snippet14":::
:::code language="fsharp" source="~/snippets/fsharp/System/Random/Overview/long1.fs" id="Snippet14":::
:::code language="vb" source="~/snippets/visualbasic/System/Random/Overview/long1.vb" id="Snippet14":::
An alternative technique that uses bit manipulation does not generate truly random numbers. This technique calls <xref:System.Random.Next> to generate two integers, left-shifts one by 32 bits, and ORs them together. This technique has two limitations:
1. Because bit 31 is the sign bit, the value in bit 31 of the resulting long integer is always 0. This can be addressed by generating a random 0 or 1, left-shifting it 31 bits, and ORing it with the original random long integer.
2. More seriously, because the probability that the value returned by <xref:System.Random.Next> will be 0, there will be few if any random numbers in the range 0x0-0x00000000FFFFFFFF.
## Retrieve bytes in a specified range
The overloads of the <xref:System.Random.Next*> method allow you to specify the range of random numbers, but the <xref:System.Random.NextBytes*> method does not. The following example implements a `NextBytes` method that lets you specify the range of the returned bytes. It defines a `Random2` class that derives from <xref:System.Random> and overloads its `NextBytes` method.
:::code language="csharp" source="~/snippets/csharp/System/Random/Overview/bytes1.cs" id="Snippet9":::
:::code language="fsharp" source="~/snippets/fsharp/System/Random/Overview/bytes1.fs" id="Snippet9":::
:::code language="vb" source="~/snippets/visualbasic/System/Random/Overview/bytes1.vb" id="Snippet9":::
The `NextBytes(Byte[], Byte, Byte)` method wraps a call to the <xref:System.Random.Next(System.Int32,System.Int32)> method and specifies the minimum value and one greater than the maximum value (in this case, 0 and 101) that we want returned in the byte array. Because we are sure that the integer values returned by the <xref:System.Random.Next*> method are within the range of the <xref:System.Byte> data type, we can safely cast them (in C# and F#) or convert them (in Visual Basic) from integers to bytes.
## Retrieve an element from an array or collection at random
Random numbers often serve as indexes to retrieve values from arrays or collections. To retrieve a random index value, you can call the <xref:System.Random.Next(System.Int32,System.Int32)> method, and use the lower bound of the array as the value of its `minValue` argument and one greater than the upper bound of the array as the value of its `maxValue` argument. For a zero-based array, this is equivalent to its <xref:System.Array.Length> property, or one greater than the value returned by the <xref:System.Array.GetUpperBound*?displayProperty=nameWithType> method. The following example randomly retrieves the name of a city in the United States from an array of cities.
:::code language="csharp" source="~/snippets/csharp/System/Random/Overview/array1.cs" id="Snippet10":::
:::code language="fsharp" source="~/snippets/fsharp/System/Random/Overview/array1.fs" id="Snippet10":::
:::code language="vb" source="~/snippets/visualbasic/System/Random/Overview/array1.vb" id="Snippet10":::
## Retrieve a unique element from an array or collection
A random number generator can always return duplicate values. As the range of numbers becomes smaller or the number of values generated becomes larger, the probability of duplicates grows. If random values must be unique, more numbers are generated to compensate for duplicates, resulting in increasingly poor performance.
There are a number of techniques to handle this scenario. One common solution is to create an array or collection that contains the values to be retrieved, and a parallel array that contains random floating-point numbers. The second array is populated with random numbers at the time the first array is created, and the <xref:System.Array.Sort(System.Array,System.Array)?displayProperty=nameWithType> method is used to sort the first array by using the values in the parallel array.
For example, if you're developing a Solitaire game, you want to ensure that each card is used only once. Instead of generating random numbers to retrieve a card and tracking whether that card has already been dealt, you can create a parallel array of random numbers that can be used to sort the deck. Once the deck is sorted, your app can maintain a pointer to indicate the index of the next card on the deck.
The following example illustrates this approach. It defines a `Card` class that represents a playing card and a `Dealer` class that deals a deck of shuffled cards. The `Dealer` class constructor populates two arrays: a `deck` array that has class scope and that represents all the cards in the deck; and a local `order` array that has the same number of elements as the `deck` array and is populated with randomly generated <xref:System.Double> values. The <xref:System.Array.Sort(System.Array,System.Array)?displayProperty=nameWithType> method is then called to sort the `deck` array based on the values in the `order` array.
:::code language="csharp" source="~/snippets/csharp/System/Random/Overview/uniquearray1.cs" id="Snippet11":::
:::code language="fsharp" source="~/snippets/fsharp/System/Random/Overview/uniquearray1.fs" id="Snippet11":::
:::code language="vb" source="~/snippets/visualbasic/System/Random/Overview/uniquearray1.vb" id="Snippet11":::
]]></format>
</remarks>
<example>
<format type="text/markdown"><![CDATA[
The following example creates a single random number generator and calls its <xref:System.Random.NextBytes*>, <xref:System.Random.Next*>, and <xref:System.Random.NextDouble*> methods to generate sequences of random numbers within different ranges.
:::code language="csharp" source="~/snippets/csharp/System/Random/Overview/Random2.cs" id="Snippet2":::
:::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/Random2.fs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/System/Random/Overview/Random2.vb" id="Snippet2":::
The following example generates a random integer that it uses as an index to retrieve a string value from an array.
:::code language="csharp" source="~/snippets/csharp/System/Random/Overview/next1.cs" id="Snippet3":::
:::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Next/FS/next1.fs" id="Snippet3":::
:::code language="vb" source="~/snippets/visualbasic/System/Random/Overview/next1.vb" id="Snippet3":::
]]></format>
</example>
<block subset="none" type="overrides">
<para>The <see cref="M:System.Random.Next" />, <see cref="M:System.Random.Next(System.Int32,System.Int32)" />, and <see cref="M:System.Random.NextBytes(System.Byte[])" /> methods don't necessarily call the derived class implementation of the <see cref="M:System.Random.Sample" /> method. As a result, classes derived from <see cref="T:System.Random" /> should also override these three methods.</para>
</block>
<block subset="none" type="usage">
<para>The implementation of the random number generator in the <see cref="T:System.Random" /> class isn't guaranteed to remain the same across major versions of .NET. As a result, you shouldn't assume that the same seed will result in the same pseudo-random sequence in different versions of .NET.</para>
</block>
</Docs>
<Members>
<MemberGroup MemberName=".ctor">
<AssemblyInfo>
<AssemblyName>System.Runtime.Extensions</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
</AssemblyInfo>
<Docs>
<summary>Initializes a new instance of the <see cref="T:System.Random" /> class.</summary>
</Docs>
</MemberGroup>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="public Random ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Random.#ctor" />
<MemberSignature Language="VB.NET" Value="Public Sub New ()" />
<MemberSignature Language="C++ CLI" Value="public:
 Random();" />
<MemberType>Constructor</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime.Extensions</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.2.2.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
<AssemblyVersion>11.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Parameters />
<Docs>
<summary>Initializes a new instance of the <see cref="T:System.Random" /> class using a default seed value.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The default seed value is produced by the thread-static, pseudo-random number generator, so different <xref:System.Random> objects created in close succession produce different sets of random numbers.
Call this constructor if you want your random number generator to generate a random sequence of numbers. To generate a fixed sequence of random numbers that will be the same for different random number generators, call the <xref:System.Random.%23ctor(System.Int32)> constructor with a fixed seed value. This <xref:System.Random> constructor overload is frequently used when testing apps that use random numbers.
Once you've instantiated the random number generator, you call individual <xref:System.Random> methods, such as <xref:System.Random.Next> or <xref:System.Random.NextDouble>, to generate random numbers.
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="public Random (int Seed);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor(int32 Seed) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Random.#ctor(System.Int32)" />
<MemberSignature Language="VB.NET" Value="Public Sub New (Seed As Integer)" />
<MemberSignature Language="F#" Value="new Random : int -> Random" Usage="new System.Random Seed" />
<MemberSignature Language="C++ CLI" Value="public:
 Random(int Seed);" />
<MemberType>Constructor</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime.Extensions</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.2.2.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
<AssemblyVersion>11.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Parameters>
<Parameter Name="Seed" Type="System.Int32" />
</Parameters>
<Docs>
<param name="Seed">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>
<summary>Initializes a new instance of the <see cref="T:System.Random" /> class, using the specified seed value.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
Providing an identical seed value to different <xref:System.Random> objects causes each instance to produce identical sequences of random numbers. This is often done when testing apps that rely on random number generators.
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, as the <xref:System.Random.%23ctor> overload does. Another option is to instantiate a single <xref:System.Random> object that you use to generate all the random numbers in your application. This yields slightly better performance, since instantiating a random number generator is fairly expensive.
## Examples
The following example creates <xref:System.Random> objects with the class constructor that takes a seed parameter and generates a sequence of random integers and doubles. The example illustrates that the same sequence is generated when the <xref:System.Random> object is created again with the constructor and seed parameter.
:::code language="csharp" source="~/snippets/csharp/System/Random/.ctor/ctor.cs" id="Snippet1":::
:::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Ctor/FS/ctor.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/System/Random/.ctor/ctor.vb" id="Snippet1":::
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="GetHexString">
<MemberSignature Language="C#" Value="public string GetHexString (int stringLength, bool lowercase = false);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance string GetHexString(int32 stringLength, bool lowercase) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Random.GetHexString(System.Int32,System.Boolean)" />
<MemberSignature Language="VB.NET" Value="Public Function GetHexString (stringLength As Integer, Optional lowercase As Boolean = false) As String" />
<MemberSignature Language="F#" Value="member this.GetHexString : int * bool -> string" Usage="random.GetHexString (stringLength, lowercase)" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
<AssemblyVersion>11.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Runtime.Extensions</AssemblyName>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.String</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="stringLength" Type="System.Int32" Index="0" FrameworkAlternate="net-10.0;net-11.0" />
<Parameter Name="lowercase" Type="System.Boolean" Index="1" FrameworkAlternate="net-10.0;net-11.0" />
</Parameters>
<Docs>
<param name="stringLength">The length of string to create.</param>
<param name="lowercase">
<para>
<see langword="true" /> if the hexadecimal characters should be lowercase; <see langword="false" /> if they should be uppercase.</para>
<para>The default is <see langword="false" />.</para>
</param>
<summary>Creates a string filled with random hexadecimal characters.</summary>
<returns>A string populated with random hexadecimal characters.</returns>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="GetHexString">
<MemberSignature Language="C#" Value="public void GetHexString (Span<char> destination, bool lowercase = false);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance void GetHexString(valuetype System.Span`1<char> destination, bool lowercase) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Random.GetHexString(System.Span{System.Char},System.Boolean)" />
<MemberSignature Language="VB.NET" Value="Public Sub GetHexString (destination As Span(Of Char), Optional lowercase As Boolean = false)" />
<MemberSignature Language="F#" Value="member this.GetHexString : Span<char> * bool -> unit" Usage="random.GetHexString (destination, lowercase)" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
<AssemblyVersion>11.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Runtime.Extensions</AssemblyName>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="destination" Type="System.Span<System.Char>" Index="0" FrameworkAlternate="net-10.0;net-11.0" />
<Parameter Name="lowercase" Type="System.Boolean" Index="1" FrameworkAlternate="net-10.0;net-11.0" />
</Parameters>
<Docs>
<param name="destination">The buffer to receive the characters.</param>
<param name="lowercase">
<para>
<see langword="true" /> if the hexadecimal characters should be lowercase; <see langword="false" /> if they should be uppercase.</para>
<para>The default is <see langword="false" />.</para>
</param>
<summary>Fills a buffer with random hexadecimal characters.</summary>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="GetItems<T>">
<MemberSignature Language="C#" Value="public T[] GetItems<T> (ReadOnlySpan<T> choices, int length);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance !!T[] GetItems<T>(valuetype System.ReadOnlySpan`1<!!T> choices, int32 length) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Random.GetItems``1(System.ReadOnlySpan{``0},System.Int32)" />
<MemberSignature Language="VB.NET" Value="Public Function GetItems(Of T) (choices As ReadOnlySpan(Of T), length As Integer) As T()" />
<MemberSignature Language="F#" Value="member this.GetItems : ReadOnlySpan<'T> * int -> 'T[]" Usage="random.GetItems (choices, length)" />
<MemberSignature Language="C++ CLI" Value="public:
generic <typename T>
 cli::array <T> ^ GetItems(ReadOnlySpan<T> choices, int length);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
<AssemblyVersion>11.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Runtime.Extensions</AssemblyName>
</AssemblyInfo>
<ReturnValue>
<ReturnType>T[]</ReturnType>
</ReturnValue>
<TypeParameters>
<TypeParameter Name="T">
<Attributes>
<Attribute>
<AttributeName Language="C#">[System.Runtime.CompilerServices.Nullable(2)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.Nullable(2)>]</AttributeName>
</Attribute>
</Attributes>
</TypeParameter>
</TypeParameters>
<Parameters>
<Parameter Name="choices" Type="System.ReadOnlySpan<T>" Index="0" FrameworkAlternate="net-10.0;net-11.0;net-8.0;net-9.0">
<Attributes>
<Attribute>
<AttributeName Language="C#">[System.Runtime.CompilerServices.Nullable(new System.Byte[] { 0, 1 })]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.Nullable(new System.Byte[] { 0, 1 })>]</AttributeName>
</Attribute>
</Attributes>
</Parameter>
<Parameter Name="length" Type="System.Int32" Index="1" FrameworkAlternate="net-10.0;net-11.0;net-8.0;net-9.0" />
</Parameters>
<Docs>
<typeparam name="T">The type of array.</typeparam>
<param name="choices">The items to use to populate the array.</param>
<param name="length">The length of array to return.</param>
<summary>Creates an array populated with items chosen at random from the provided set of choices.</summary>
<returns>An array populated with random items.</returns>
<remarks>The method uses <see cref="M:System.Random.Next(System.Int32)" /> to select items randomly from <paramref name="choices" /> by index. This is used to populate a newly-created array.</remarks>
<exception cref="T:System.ArgumentException">
<paramref name="choices" /> is empty.</exception>
<exception cref="T:System.ArgumentOutOfRangeException">
<paramref name="length" /> is not zero or a positive number.</exception>
</Docs>
</Member>
<Member MemberName="GetItems<T>">
<MemberSignature Language="C#" Value="public void GetItems<T> (ReadOnlySpan<T> choices, Span<T> destination);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance void GetItems<T>(valuetype System.ReadOnlySpan`1<!!T> choices, valuetype System.Span`1<!!T> destination) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Random.GetItems``1(System.ReadOnlySpan{``0},System.Span{``0})" />
<MemberSignature Language="VB.NET" Value="Public Sub GetItems(Of T) (choices As ReadOnlySpan(Of T), destination As Span(Of T))" />
<MemberSignature Language="F#" Value="member this.GetItems : ReadOnlySpan<'T> * Span<'T> -> unit" Usage="random.GetItems (choices, destination)" />
<MemberSignature Language="C++ CLI" Value="public:
generic <typename T>
 void GetItems(ReadOnlySpan<T> choices, Span<T> destination);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
<AssemblyVersion>11.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Runtime.Extensions</AssemblyName>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<TypeParameters>
<TypeParameter Name="T" />
</TypeParameters>
<Parameters>
<Parameter Name="choices" Type="System.ReadOnlySpan<T>" Index="0" FrameworkAlternate="net-10.0;net-11.0;net-8.0;net-9.0">
<Attributes>
<Attribute>
<AttributeName Language="C#">[System.Runtime.CompilerServices.Nullable(new System.Byte[] { 0, 1 })]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.Nullable(new System.Byte[] { 0, 1 })>]</AttributeName>
</Attribute>
</Attributes>
</Parameter>
<Parameter Name="destination" Type="System.Span<T>" Index="1" FrameworkAlternate="net-10.0;net-11.0;net-8.0;net-9.0">
<Attributes>
<Attribute>
<AttributeName Language="C#">[System.Runtime.CompilerServices.Nullable(new System.Byte[] { 0, 1 })]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.Nullable(new System.Byte[] { 0, 1 })>]</AttributeName>
</Attribute>
</Attributes>
</Parameter>
</Parameters>
<Docs>
<typeparam name="T">The type of span.</typeparam>
<param name="choices">The items to use to populate the span.</param>
<param name="destination">The span to be filled with items.</param>
<summary>Fills the elements of a specified span with items chosen at random from the provided set of choices.</summary>
<remarks>The method uses <see cref="M:System.Random.Next(System.Int32)" /> to select items randomly from <paramref name="choices" /> by index and populate <paramref name="destination" />.</remarks>
<exception cref="T:System.ArgumentException">
<paramref name="choices" /> is empty.</exception>
</Docs>
</Member>
<Member MemberName="GetItems<T>">
<MemberSignature Language="C#" Value="public T[] GetItems<T> (T[] choices, int length);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance !!T[] GetItems<T>(!!T[] choices, int32 length) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Random.GetItems``1(``0[],System.Int32)" />
<MemberSignature Language="VB.NET" Value="Public Function GetItems(Of T) (choices As T(), length As Integer) As T()" />
<MemberSignature Language="F#" Value="member this.GetItems : 'T[] * int -> 'T[]" Usage="random.GetItems (choices, length)" />
<MemberSignature Language="C++ CLI" Value="public:
generic <typename T>
 cli::array <T> ^ GetItems(cli::array <T> ^ choices, int length);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
<AssemblyVersion>11.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Runtime.Extensions</AssemblyName>
</AssemblyInfo>
<ReturnValue>
<ReturnType>T[]</ReturnType>
</ReturnValue>
<TypeParameters>
<TypeParameter Name="T">
<Attributes>
<Attribute>
<AttributeName Language="C#">[System.Runtime.CompilerServices.Nullable(2)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.Nullable(2)>]</AttributeName>
</Attribute>
</Attributes>
</TypeParameter>
</TypeParameters>
<Parameters>
<Parameter Name="choices" Type="T[]" Index="0" FrameworkAlternate="net-10.0;net-11.0;net-8.0;net-9.0" />
<Parameter Name="length" Type="System.Int32" Index="1" FrameworkAlternate="net-10.0;net-11.0;net-8.0;net-9.0" />
</Parameters>
<Docs>
<typeparam name="T">The type of array.</typeparam>
<param name="choices">The items to use to populate the array.</param>
<param name="length">The length of array to return.</param>
<summary>Creates an array populated with items chosen at random from the provided set of choices.</summary>
<returns>An array populated with random items.</returns>
<remarks>The method uses <see cref="M:System.Random.Next(System.Int32)" /> to select items randomly from <paramref name="choices" /> by index. This is used to populate a newly-created array.</remarks>
<exception cref="T:System.ArgumentException">
<paramref name="choices" /> is empty.</exception>
<exception cref="T:System.ArgumentNullException">
<paramref name="choices" /> is <see langword="null" />.</exception>
<exception cref="T:System.ArgumentOutOfRangeException">
<paramref name="length" /> is not zero or a positive number.</exception>
</Docs>
</Member>
<Member MemberName="GetString">
<MemberSignature Language="C#" Value="public string GetString (ReadOnlySpan<char> choices, int length);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance string GetString(valuetype System.ReadOnlySpan`1<char> choices, int32 length) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Random.GetString(System.ReadOnlySpan{System.Char},System.Int32)" />
<MemberSignature Language="VB.NET" Value="Public Function GetString (choices As ReadOnlySpan(Of Char), length As Integer) As String" />
<MemberSignature Language="F#" Value="member this.GetString : ReadOnlySpan<char> * int -> string" Usage="random.GetString (choices, length)" />
<MemberSignature Language="C++ CLI" Value="public:
 System::String ^ GetString(ReadOnlySpan<char> choices, int length);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
<AssemblyVersion>11.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Runtime.Extensions</AssemblyName>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.String</ReturnType>
<Attributes>
<Attribute FrameworkAlternate="net-10.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.Nullable(1)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.Nullable(1)>]</AttributeName>
</Attribute>
</Attributes>
</ReturnValue>
<Parameters>
<Parameter Name="choices" Type="System.ReadOnlySpan<System.Char>" Index="0" FrameworkAlternate="net-10.0;net-11.0" />
<Parameter Name="length" Type="System.Int32" Index="1" FrameworkAlternate="net-10.0;net-11.0" />
</Parameters>
<Docs>
<param name="choices">The characters to use to populate the string.</param>
<param name="length">The length of string to return.</param>
<summary>Creates a string populated with characters chosen at random from <paramref name="choices" />.</summary>
<returns>A string populated with items selected at random from <paramref name="choices" />.</returns>
<remarks>To be added.</remarks>
<exception cref="T:System.ArgumentException">
<paramref name="choices" /> is empty.</exception>
<exception cref="T:System.ArgumentOutOfRangeException">
<paramref name="length" /> is not zero or a positive number.</exception>
<seealso cref="M:System.Random.GetItems``1(System.ReadOnlySpan{``0},System.Span{``0})" />
</Docs>
</Member>
<MemberGroup MemberName="Next">
<AssemblyInfo>
<AssemblyName>System.Runtime.Extensions</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
</AssemblyInfo>
<Docs>
<summary>Returns a random integer.</summary>
<remarks>To be added.</remarks>
</Docs>
</MemberGroup>
<Member MemberName="Next">
<MemberSignature Language="C#" Value="public virtual int Next ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig newslot virtual instance int32 Next() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Random.Next" />
<MemberSignature Language="VB.NET" Value="Public Overridable Function Next () As Integer" />
<MemberSignature Language="F#" Value="abstract member Next : unit -> int
override this.Next : unit -> int" Usage="random.Next " />
<MemberSignature Language="C++ CLI" Value="public:
 virtual int Next();" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime.Extensions</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.2.2.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
<AssemblyVersion>11.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Int32</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Returns a non-negative random integer.</summary>
<returns>A 32-bit signed integer that is greater than or equal to 0 and less than <see cref="F:System.Int32.MaxValue">Int32.MaxValue</see>.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
<xref:System.Random.Next*?displayProperty=nameWithType> generates a random number whose value ranges from 0 to less than <xref:System.Int32.MaxValue?displayProperty=nameWithType>. To generate a random number whose value ranges from 0 to some other positive number, use the <xref:System.Random.Next(System.Int32)?displayProperty=nameWithType> method overload. To generate a random number within a different range, use the <xref:System.Random.Next(System.Int32,System.Int32)?displayProperty=nameWithType> method overload.
## Examples
The following example makes repeated calls to the <xref:System.Random.Next*> method to generate 10 random numbers.
:::code language="csharp" source="~/snippets/csharp/System/Random/Overview/next3.cs" id="Snippet5":::
:::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Next/FS/next3.fs" id="Snippet5":::
:::code language="vb" source="~/snippets/visualbasic/System/Random/Overview/next3.vb" id="Snippet5":::
The following example derives a class from <xref:System.Random> to generate a sequence of random numbers whose distribution differs from the uniform distribution generated by the <xref:System.Random.Sample*> method of the base class. It overrides the <xref:System.Random.Sample*> method to provide the distribution of random numbers, and overrides the <xref:System.Random.Next*?displayProperty=nameWithType> method to use series of random numbers.
:::code language="csharp" source="~/snippets/csharp/System/Random/Next/sample.cs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/System/Random/Next/sample.vb" id="Snippet1":::
]]></format>
</remarks>
<block subset="none" type="overrides">
<para>If you derive a class from <see cref="T:System.Random" /> and override the <see cref="M:System.Random.Sample" /> method, the distribution provided by the derived class implementation of the <see cref="M:System.Random.Sample" /> method is not used in calls to the base class implementation of the <see cref="M:System.Random.Next" /> method. Instead, the uniform distribution returned by the base <see cref="T:System.Random" /> class is used. This behavior improves the overall performance of the <see cref="T:System.Random" /> class. To modify this behavior to call the <see cref="M:System.Random.Sample" /> method in the derived class, you must also override the <see cref="M:System.Random.Next" /> method.</para>
</block>
<altmember cref="T:System.Int32" />
</Docs>
</Member>
<Member MemberName="Next">
<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" />
<MemberSignature Language="DocId" Value="M:System.Random.Next(System.Int32)" />
<MemberSignature Language="VB.NET" Value="Public Overridable Function Next (maxValue As Integer) As Integer" />
<MemberSignature Language="F#" Value="abstract member Next : int -> int
override this.Next : int -> int" Usage="random.Next maxValue" />
<MemberSignature Language="C++ CLI" Value="public:
 virtual int Next(int maxValue);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime.Extensions</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.2.2.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
<AssemblyVersion>11.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Int32</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="maxValue" Type="System.Int32" />
</Parameters>
<Docs>
<param name="maxValue">The exclusive upper bound of the random number to be generated. <paramref name="maxValue" /> must be greater than or equal to 0.</param>
<summary>Returns a non-negative random integer that is less than the specified maximum.</summary>
<returns>A 32-bit signed integer that is greater than or equal to 0, and less than <paramref name="maxValue" />; that is, the range of return values ordinarily includes 0 but not <paramref name="maxValue" />. However, if <paramref name="maxValue" /> equals 0, 0 is returned.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:System.Random.Next(System.Int32)> overload returns random integers that range from 0 to `maxValue` - 1. However, if `maxValue` is 0, the method returns 0.
## Examples
The following example generates random integers with various overloads of the <xref:System.Random.Next*> method.
:::code language="csharp" source="~/snippets/csharp/System/Random/Overview/next.cs" id="Snippet1":::
:::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Next/FS/next.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/System/Random/Overview/next.vb" id="Snippet1":::
The following example generates a random integer that it uses as an index to retrieve a string value from an array. Because the highest index of the array is one less than its length, the value of the <xref:System.Array.Length?displayProperty=nameWithType> property is supplied as the `maxValue` parameter.
:::code language="csharp" source="~/snippets/csharp/System/Random/Overview/next1.cs" id="Snippet3":::
:::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Next/FS/next1.fs" id="Snippet3":::
:::code language="vb" source="~/snippets/visualbasic/System/Random/Overview/next1.vb" id="Snippet3":::
]]></format>
</remarks>
<exception cref="T:System.ArgumentOutOfRangeException">
<paramref name="maxValue" /> is less than 0.</exception>
<altmember cref="T:System.Int32" />
</Docs>
</Member>
<Member MemberName="Next">
<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" />
<MemberSignature Language="DocId" Value="M:System.Random.Next(System.Int32,System.Int32)" />
<MemberSignature Language="VB.NET" Value="Public Overridable Function Next (minValue As Integer, maxValue As Integer) As Integer" />
<MemberSignature Language="F#" Value="abstract member Next : int * int -> int
override this.Next : int * int -> int" Usage="random.Next (minValue, maxValue)" />
<MemberSignature Language="C++ CLI" Value="public:
 virtual int Next(int minValue, int maxValue);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime.Extensions</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.2.2.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
<AssemblyVersion>11.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>
<param name="minValue">The inclusive lower bound of the random number returned.</param>
<param name="maxValue">The exclusive upper bound of the random number returned. <paramref name="maxValue" /> must be greater than or equal to <paramref name="minValue" />.</param>
<summary>Returns a random integer that is within a specified range.</summary>
<returns>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.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:System.Random.Next(System.Int32,System.Int32)> overload returns random integers that range from `minValue` to `maxValue` - 1. However, if `maxValue` equals `minValue`, the method returns `minValue`.
Unlike the other overloads of the <xref:System.Random.Next*> method, which return only non-negative values, this method can return a negative random integer.
## Examples
The following example uses the <xref:System.Random.Next(System.Int32,System.Int32)?displayProperty=nameWithType> method to generate random integers with three distinct ranges. Note that the exact output from the example depends on the system-supplied seed value passed to the <xref:System.Random> class constructor.
:::code language="csharp" source="~/snippets/csharp/System/Random/Overview/Next2.cs" id="Snippet2":::
:::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Next/FS/Next2.fs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/System/Random/Overview/next2.vb" id="Snippet2":::
The following example generates a random integer that it uses as an index to retrieve a string value from an array. Because the highest index of the array is one less than its length, the value of the <xref:System.Array.Length?displayProperty=nameWithType> property is supplied as a the `maxValue` parameter.
:::code language="csharp" source="~/snippets/csharp/System/Random/Overview/next4.cs" id="Snippet4":::
:::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Next/FS/next4.fs" id="Snippet4":::
:::code language="vb" source="~/snippets/visualbasic/System/Random/Overview/next4.vb" id="Snippet4":::
]]></format>
</remarks>
<exception cref="T:System.ArgumentOutOfRangeException">
<paramref name="minValue" /> is greater than <paramref name="maxValue" />.</exception>
<block subset="none" type="overrides">
<para>If you derive a class from <see cref="T:System.Random" /> and override the <see cref="M:System.Random.Sample" /> method, the distribution provided by the derived class implementation of the <see cref="M:System.Random.Sample" /> method is not used in calls to the base class implementation of the <see cref="M:System.Random.Next(System.Int32,System.Int32)" /> method overload if the difference between the <paramref name="minValue" /> and <paramref name="maxValue" /> parameters is greater than <see cref="F:System.Int32.MaxValue">Int32.MaxValue</see>. Instead, the uniform distribution returned by the base <see cref="T:System.Random" /> class is used. This behavior improves the overall performance of the <see cref="T:System.Random" /> class. To modify this behavior to call the <see cref="M:System.Random.Sample" /> method in the derived class, you must also override the <see cref="M:System.Random.Next(System.Int32,System.Int32)" /> method overload.</para>
</block>
<altmember cref="T:System.Int32" />
</Docs>
</Member>
<Member MemberName="NextBinaryFloat<T>">
<MemberSignature Language="C#" Value="public T NextBinaryFloat<T> () where T : System.Numerics.IBinaryFloatingPointIeee754<T>;" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance !!T NextBinaryFloat<(class System.Numerics.IBinaryFloatingPointIeee754`1<!!T>) T>() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Random.NextBinaryFloat``1" />
<MemberSignature Language="VB.NET" Value="Public Function NextBinaryFloat(Of T As IBinaryFloatingPointIeee754(Of T)) () As T" />
<MemberSignature Language="F#" Value="member this.NextBinaryFloat : unit -> 'T (requires 'T :> System.Numerics.IBinaryFloatingPointIeee754<'T>)" Usage="random.NextBinaryFloat " />
<MemberSignature Language="C++ CLI" Value="public:
generic <typename T>
 where T : System::Numerics::IBinaryFloatingPointIeee754<T> T NextBinaryFloat();" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>11.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Runtime.Extensions</AssemblyName>
</AssemblyInfo>
<ReturnValue>
<ReturnType>T</ReturnType>
</ReturnValue>
<TypeParameters>
<TypeParameter Name="T">
<Attributes>
<Attribute>
<AttributeName Language="C#">[System.Runtime.CompilerServices.Nullable(0)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.Nullable(0)>]</AttributeName>
</Attribute>
</Attributes>
<Constraints>
<InterfaceName>System.Numerics.IBinaryFloatingPointIeee754<T></InterfaceName>