Skip to content

Commit b7b4290

Browse files
committed
thread static random
1 parent 276f340 commit b7b4290

File tree

2 files changed

+4
-20
lines changed

2 files changed

+4
-20
lines changed

ObjectFiller/Random.cs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,19 @@ internal static class Random
2222
/// <summary>
2323
/// A instance of <see cref="Random"/>
2424
/// </summary>
25+
[ThreadStatic]
2526
private static readonly System.Random Rnd;
2627

2728
/// <summary>
2829
/// Initializes static members of the <see cref="Random"/> class.
2930
/// </summary>
3031
static Random()
3132
{
32-
#if NET3X || NETSTD
33+
#if NETSTD
3334
Rnd = new System.Random();
3435
#else
35-
Rnd = ThreadSafeRandomProvider.GetThreadRandom();
36+
int seed = Environment.TickCount;
37+
Rnd = new System.Random(Interlocked.Increment(ref seed));
3638
#endif
3739
}
3840

@@ -125,20 +127,4 @@ internal static long NextLong()
125127
return BitConverter.ToInt64(buf, 0);
126128
}
127129
}
128-
129-
#if (!NET3X && !NETSTD)
130-
public static class ThreadSafeRandomProvider
131-
{
132-
private static int _seed = Environment.TickCount;
133-
134-
private static readonly ThreadLocal<System.Random> _randomWrapper = new ThreadLocal<System.Random>(() =>
135-
new System.Random(Interlocked.Increment(ref _seed))
136-
);
137-
138-
public static System.Random GetThreadRandom()
139-
{
140-
return _randomWrapper.Value;
141-
}
142-
}
143-
#endif
144130
}

ObjectFiller/Randomizer.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ namespace Tynamix.ObjectFiller
1212
using System;
1313
using System.Collections.Generic;
1414
using System.Linq;
15-
using System.Reflection;
16-
using System.Runtime.CompilerServices;
1715

1816
/// <summary>
1917
/// This class is a easy way to get random values.

0 commit comments

Comments
 (0)