| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | |
|
| | 6 | | namespace Azure.Core.Pipeline |
| | 7 | | { |
| | 8 | | internal class ThreadSafeRandom : Random |
| | 9 | | { |
| 210 | 10 | | private readonly Random _random = new Random(); |
| | 11 | |
|
| | 12 | | public override int Next() |
| | 13 | | { |
| 0 | 14 | | lock (_random) |
| | 15 | | { |
| 0 | 16 | | return _random.Next(); |
| | 17 | | } |
| 0 | 18 | | } |
| | 19 | |
|
| | 20 | | public override int Next(int minValue, int maxValue) |
| | 21 | | { |
| 564 | 22 | | lock (_random) |
| | 23 | | { |
| 564 | 24 | | return _random.Next(minValue, maxValue); |
| | 25 | | } |
| 564 | 26 | | } |
| | 27 | |
|
| | 28 | | public override int Next(int maxValue) |
| | 29 | | { |
| 0 | 30 | | lock (_random) |
| | 31 | | { |
| 0 | 32 | | return _random.Next(maxValue); |
| | 33 | | } |
| 0 | 34 | | } |
| | 35 | |
|
| | 36 | | public override double NextDouble() |
| | 37 | | { |
| 0 | 38 | | lock (_random) |
| | 39 | | { |
| 0 | 40 | | return _random.NextDouble(); |
| | 41 | | } |
| 0 | 42 | | } |
| | 43 | |
|
| | 44 | | public override void NextBytes(byte[] buffer) |
| | 45 | | { |
| 0 | 46 | | lock (_random) |
| | 47 | | { |
| 0 | 48 | | _random.NextBytes(buffer); |
| 0 | 49 | | } |
| 0 | 50 | | } |
| | 51 | | } |
| | 52 | | } |