forked from SciSharp/NumSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnp.random.cs
More file actions
90 lines (75 loc) · 2.61 KB
/
np.random.cs
File metadata and controls
90 lines (75 loc) · 2.61 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
namespace NumSharp
{
/// <summary>
/// A class that serves as numpy.random.RandomState in python.
/// </summary>
/// <remarks>https://docs.scipy.org/doc/numpy-1.16.1/reference/routines.random.html</remarks>
public partial class NumPyRandom
{
protected internal Randomizer randomizer;
public int Seed { get; set; }
#region Constructors
protected internal NumPyRandom(Randomizer randomizer)
{
this.randomizer = randomizer;
}
protected internal NumPyRandom(NativeRandomState nativeRandomState)
{
set_state(nativeRandomState);
}
protected internal NumPyRandom(int seed) : this(new Randomizer(seed)) {
Seed = seed;
}
protected internal NumPyRandom() : this(new Randomizer()) { }
#endregion
#region RandomState
/// <summary>
/// Returns a new instance of <see cref="NumPyRandom"/>.
/// </summary>
public NumPyRandom RandomState()
{
return new NumPyRandom();
}
/// <summary>
/// Returns a new instance of <see cref="NumPyRandom"/>.
/// </summary>
public NumPyRandom RandomState(int seed)
{
return new NumPyRandom(seed);
}
/// <summary>
/// Returns a new instance of <see cref="NumPyRandom"/>.
/// </summary>
public NumPyRandom RandomState(NativeRandomState state)
{
return new NumPyRandom(state);
}
#endregion
/// <summary>
/// Seeds the generator.
/// It can be called again to re-seed the generator.
/// </summary>
public void seed(int seed)
{
Seed = seed;
randomizer = new Randomizer(seed);
}
/// <summary>
/// Set the internal state of the generator from a <see cref="NumPyRandom"/>.
/// for use if one has reason to manually (re-)set the internal state of the pseudo-random number generating algorithm.
/// </summary>
/// <param name="nativeRandomState">The state to restore onto this <see cref="NumPyRandom"/></param>
public void set_state(NativeRandomState nativeRandomState)
{
randomizer = nativeRandomState.Restore();
}
/// <summary>
/// Return a <see cref="NumPyRandom"/> representing the internal state of the generator.
/// </summary>
/// <returns></returns>
public NativeRandomState get_state()
{
return randomizer.Save();
}
}
}