redshift 1.3.24 → 1.3.30
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +49 -0
- data/RELEASE-NOTES +34 -3
- data/Rakefile +81 -0
- data/bench/bench +1 -1
- data/bench/formula.rb +2 -3
- data/examples/pid.rb +6 -6
- data/examples/robots/lib/shell-world.rb +1 -1
- data/examples/scheduler.rb +6 -1
- data/ext/redshift/dvector-float/dvector-float.c +184 -0
- data/ext/redshift/dvector-float/dvector-float.h +36 -0
- data/ext/redshift/dvector-float/dvector-float.rb +33 -0
- data/ext/redshift/dvector-float/extconf.rb +2 -0
- data/lib/redshift/redshift.rb +5 -5
- data/lib/redshift/target/c/component-gen.rb +1 -1
- data/lib/redshift/target/c/flow-gen.rb +1 -1
- data/lib/redshift/target/c/flow/delay.rb +1 -1
- data/lib/redshift/target/c/world-gen.rb +101 -101
- data/lib/redshift/util/isaac.rb +2 -2
- data/lib/redshift/util/tkar-driver.rb +1 -1
- data/test/test.rb +1 -1
- data/test/test_buffer.rb +2 -2
- data/test/test_connect.rb +2 -2
- data/test/test_connect_parallel.rb +2 -2
- data/test/test_connect_strict.rb +4 -5
- data/test/test_constant.rb +2 -4
- data/test/test_delay.rb +2 -2
- data/test/test_derivative.rb +2 -2
- data/test/test_discrete.rb +2 -4
- data/test/test_discrete_isolated.rb +2 -4
- data/test/test_dvector-float.rb +110 -0
- data/test/test_dvector.rb +15 -17
- data/test/test_exit.rb +2 -4
- data/test/test_flow.rb +2 -4
- data/test/test_flow_link.rb +2 -4
- data/test/test_flow_sub.rb +2 -4
- data/test/test_flow_trans.rb +23 -25
- data/test/test_inherit.rb +2 -4
- data/test/test_inherit_event.rb +2 -4
- data/test/test_inherit_flow.rb +2 -4
- data/test/test_inherit_link.rb +2 -4
- data/test/test_inherit_setup.rb +2 -4
- data/test/test_inherit_state.rb +2 -4
- data/test/test_inherit_transition.rb +2 -4
- data/test/test_numerics.rb +2 -4
- data/test/test_queue.rb +3 -3
- data/test/test_queue_alone.rb +2 -2
- data/test/test_reset.rb +2 -4
- data/test/test_setup.rb +2 -4
- data/test/test_strict_continuity.rb +2 -4
- data/test/test_strict_reset_error.rb +2 -4
- data/test/test_strictness_error.rb +2 -4
- data/test/test_sync.rb +2 -2
- data/test/test_world.rb +2 -4
- metadata +80 -106
- data/.bnsignore +0 -27
- data/.gitignore +0 -9
- data/README +0 -25
- data/TODO +0 -431
- data/bench/aug17-ruby19.bench +0 -86
- data/bench/aug17.bench +0 -86
- data/bench/aug7.bench +0 -86
- data/bench/prof.html +0 -0
- data/examples/robots/README +0 -49
- data/ext/redshift/util/isaac/extconf.rb +0 -2
- data/ext/redshift/util/isaac/isaac.c +0 -129
- data/ext/redshift/util/isaac/rand.c +0 -140
- data/ext/redshift/util/isaac/rand.h +0 -61
- data/rakefile +0 -50
data/bench/aug17-ruby19.bench
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
alg-state:
|
2
|
-
- 0 comps X 1000 steps X 0 non-alg: 0.00
|
3
|
-
- 10 comps X 1000 steps X 0 non-alg: 0.00
|
4
|
-
- 100 comps X 1000 steps X 0 non-alg: 0.01
|
5
|
-
- 1000 comps X 1000 steps X 0 non-alg: 0.06
|
6
|
-
- 10000 comps X 1000 steps X 0 non-alg: 2.79
|
7
|
-
algebraic:
|
8
|
-
- 1 comps X 1000000 steps: 2.10
|
9
|
-
- 10 comps X 100000 steps: 0.54
|
10
|
-
- 100 comps X 10000 steps: 0.47
|
11
|
-
- 1000 comps X 1000 steps: 0.44
|
12
|
-
- 10000 comps X 100 steps: 1.09
|
13
|
-
- 100000 comps X 10 steps: 1.26
|
14
|
-
connect:
|
15
|
-
- 10 comps X 100000 steps: 0.30
|
16
|
-
- 100 comps X 10000 steps: 0.09
|
17
|
-
- 1000 comps X 1000 steps: 0.10
|
18
|
-
- 10000 comps X 100 steps: 0.29
|
19
|
-
- 100000 comps X 10 steps: 0.50
|
20
|
-
continuous:
|
21
|
-
- 1 comps X 1000000 steps: 1.91
|
22
|
-
- 10 comps X 100000 steps: 0.40
|
23
|
-
- 100 comps X 10000 steps: 0.31
|
24
|
-
- 1000 comps X 1000 steps: 0.29
|
25
|
-
- 10000 comps X 100 steps: 0.85
|
26
|
-
- 100000 comps X 10 steps: 1.05
|
27
|
-
discrete:
|
28
|
-
- 1 comps X 1000000 steps X 0 watchers: 2.39
|
29
|
-
- 10 comps X 100000 steps X 0 watchers: 0.46
|
30
|
-
- 100 comps X 10000 steps X 0 watchers: 0.20
|
31
|
-
- 1000 comps X 1000 steps X 0 watchers: 0.21
|
32
|
-
- 10000 comps X 100 steps X 0 watchers: 0.54
|
33
|
-
- 100000 comps X 10 steps X 0 watchers: 0.75
|
34
|
-
- 1 comps X 1000000 steps X 1 watchers: 3.24
|
35
|
-
- 10 comps X 100000 steps X 1 watchers: 0.74
|
36
|
-
- 100 comps X 10000 steps X 1 watchers: 0.52
|
37
|
-
- 1000 comps X 1000 steps X 1 watchers: 0.63
|
38
|
-
- 10000 comps X 100 steps X 1 watchers: 2.21
|
39
|
-
- 100000 comps X 10 steps X 1 watchers: 2.46
|
40
|
-
- 1 comps X 200000 steps X 5 watchers: 0.73
|
41
|
-
- 10 comps X 20000 steps X 5 watchers: 0.43
|
42
|
-
- 100 comps X 2000 steps X 5 watchers: 0.50
|
43
|
-
- 1000 comps X 200 steps X 5 watchers: 0.86
|
44
|
-
- 10000 comps X 20 steps X 5 watchers: 2.06
|
45
|
-
- 100000 comps X 2 steps X 5 watchers: 3.72
|
46
|
-
euler:
|
47
|
-
- 1 comps X 1000000 steps: 1.86
|
48
|
-
- 10 comps X 100000 steps: 0.30
|
49
|
-
- 100 comps X 10000 steps: 0.22
|
50
|
-
- 1000 comps X 1000 steps: 0.21
|
51
|
-
- 10000 comps X 100 steps: 0.77
|
52
|
-
- 100000 comps X 10 steps: 0.94
|
53
|
-
formula:
|
54
|
-
- 1 comps X 100000 steps: 0.31
|
55
|
-
- 10 comps X 10000 steps: 0.13
|
56
|
-
- 100 comps X 1000 steps: 0.12
|
57
|
-
- 1000 comps X 100 steps: 0.12
|
58
|
-
- 10000 comps X 10 steps: 0.17
|
59
|
-
half-strict:
|
60
|
-
- 10 comps X 100000 steps: 3.09
|
61
|
-
- 100 comps X 10000 steps: 1.23
|
62
|
-
- 1000 comps X 1000 steps: 1.15
|
63
|
-
- 10000 comps X 100 steps: 1.68
|
64
|
-
- 100000 comps X 10 steps: 2.42
|
65
|
-
inertness:
|
66
|
-
- 0 comps X 10000 steps X 0 non-inert: 0.01
|
67
|
-
- 1000 comps X 10000 steps X 0 non-inert: 0.43
|
68
|
-
- 0 comps X 10000 steps X 1 non-inert: 0.12
|
69
|
-
- 1000 comps X 10000 steps X 1 non-inert: 0.54
|
70
|
-
linked-flows:
|
71
|
-
- 1 comps X 1000000 steps: 2.23
|
72
|
-
- 10 comps X 100000 steps: 0.61
|
73
|
-
- 100 comps X 10000 steps: 0.64
|
74
|
-
- 1000 comps X 1000 steps: 0.60
|
75
|
-
- 10000 comps X 100 steps: 2.09
|
76
|
-
- 100000 comps X 10 steps: 2.37
|
77
|
-
queues:
|
78
|
-
- 1 senders X 100000 steps X 1 receivers: 0.22
|
79
|
-
- 10 senders X 10000 steps X 1 receivers: 0.04
|
80
|
-
- 100 senders X 1000 steps X 1 receivers: 0.02
|
81
|
-
- 1 senders X 10000 steps X 10 receivers: 0.03
|
82
|
-
- 10 senders X 1000 steps X 10 receivers: 0.01
|
83
|
-
- 100 senders X 100 steps X 10 receivers: 0.01
|
84
|
-
- 1 senders X 1000 steps X 100 receivers: 0.01
|
85
|
-
- 10 senders X 100 steps X 100 receivers: 0.01
|
86
|
-
- 100 senders X 10 steps X 100 receivers: 0.02
|
data/bench/aug17.bench
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
alg-state:
|
2
|
-
- 0 comps X 1000 steps X 0 non-alg: 0.00
|
3
|
-
- 10 comps X 1000 steps X 0 non-alg: 0.00
|
4
|
-
- 100 comps X 1000 steps X 0 non-alg: 0.01
|
5
|
-
- 1000 comps X 1000 steps X 0 non-alg: 0.08
|
6
|
-
- 10000 comps X 1000 steps X 0 non-alg: 3.62
|
7
|
-
algebraic:
|
8
|
-
- 1 comps X 1000000 steps: 2.69
|
9
|
-
- 10 comps X 100000 steps: 0.60
|
10
|
-
- 100 comps X 10000 steps: 0.46
|
11
|
-
- 1000 comps X 1000 steps: 0.46
|
12
|
-
- 10000 comps X 100 steps: 1.30
|
13
|
-
- 100000 comps X 10 steps: 1.53
|
14
|
-
connect:
|
15
|
-
- 10 comps X 100000 steps: 0.28
|
16
|
-
- 100 comps X 10000 steps: 0.07
|
17
|
-
- 1000 comps X 1000 steps: 0.10
|
18
|
-
- 10000 comps X 100 steps: 0.38
|
19
|
-
- 100000 comps X 10 steps: 0.89
|
20
|
-
continuous:
|
21
|
-
- 1 comps X 1000000 steps: 2.54
|
22
|
-
- 10 comps X 100000 steps: 0.42
|
23
|
-
- 100 comps X 10000 steps: 0.31
|
24
|
-
- 1000 comps X 1000 steps: 0.32
|
25
|
-
- 10000 comps X 100 steps: 1.05
|
26
|
-
- 100000 comps X 10 steps: 1.32
|
27
|
-
discrete:
|
28
|
-
- 1 comps X 1000000 steps X 0 watchers: 2.49
|
29
|
-
- 10 comps X 100000 steps X 0 watchers: 0.44
|
30
|
-
- 100 comps X 10000 steps X 0 watchers: 0.18
|
31
|
-
- 1000 comps X 1000 steps X 0 watchers: 0.20
|
32
|
-
- 10000 comps X 100 steps X 0 watchers: 0.49
|
33
|
-
- 100000 comps X 10 steps X 0 watchers: 0.65
|
34
|
-
- 1 comps X 1000000 steps X 1 watchers: 3.95
|
35
|
-
- 10 comps X 100000 steps X 1 watchers: 0.71
|
36
|
-
- 100 comps X 10000 steps X 1 watchers: 0.52
|
37
|
-
- 1000 comps X 1000 steps X 1 watchers: 0.64
|
38
|
-
- 10000 comps X 100 steps X 1 watchers: 2.08
|
39
|
-
- 100000 comps X 10 steps X 1 watchers: 2.86
|
40
|
-
- 1 comps X 200000 steps X 5 watchers: 0.85
|
41
|
-
- 10 comps X 20000 steps X 5 watchers: 0.43
|
42
|
-
- 100 comps X 2000 steps X 5 watchers: 0.53
|
43
|
-
- 1000 comps X 200 steps X 5 watchers: 0.91
|
44
|
-
- 10000 comps X 20 steps X 5 watchers: 1.92
|
45
|
-
- 100000 comps X 2 steps X 5 watchers: 4.60
|
46
|
-
euler:
|
47
|
-
- 1 comps X 1000000 steps: 2.48
|
48
|
-
- 10 comps X 100000 steps: 0.34
|
49
|
-
- 100 comps X 10000 steps: 0.23
|
50
|
-
- 1000 comps X 1000 steps: 0.22
|
51
|
-
- 10000 comps X 100 steps: 0.86
|
52
|
-
- 100000 comps X 10 steps: 1.08
|
53
|
-
formula:
|
54
|
-
- 1 comps X 100000 steps: 0.34
|
55
|
-
- 10 comps X 10000 steps: 0.15
|
56
|
-
- 100 comps X 1000 steps: 0.12
|
57
|
-
- 1000 comps X 100 steps: 0.12
|
58
|
-
- 10000 comps X 10 steps: 0.19
|
59
|
-
half-strict:
|
60
|
-
- 10 comps X 100000 steps: 3.90
|
61
|
-
- 100 comps X 10000 steps: 1.25
|
62
|
-
- 1000 comps X 1000 steps: 1.05
|
63
|
-
- 10000 comps X 100 steps: 1.85
|
64
|
-
- 100000 comps X 10 steps: 3.03
|
65
|
-
inertness:
|
66
|
-
- 0 comps X 10000 steps X 0 non-inert: 0.03
|
67
|
-
- 1000 comps X 10000 steps X 0 non-inert: 0.40
|
68
|
-
- 0 comps X 10000 steps X 1 non-inert: 0.16
|
69
|
-
- 1000 comps X 10000 steps X 1 non-inert: 0.46
|
70
|
-
linked-flows:
|
71
|
-
- 1 comps X 1000000 steps: 2.29
|
72
|
-
- 10 comps X 100000 steps: 0.55
|
73
|
-
- 100 comps X 10000 steps: 0.55
|
74
|
-
- 1000 comps X 1000 steps: 0.49
|
75
|
-
- 10000 comps X 100 steps: 2.51
|
76
|
-
- 100000 comps X 10 steps: 3.10
|
77
|
-
queues:
|
78
|
-
- 1 senders X 100000 steps X 1 receivers: 0.26
|
79
|
-
- 10 senders X 10000 steps X 1 receivers: 0.04
|
80
|
-
- 100 senders X 1000 steps X 1 receivers: 0.02
|
81
|
-
- 1 senders X 10000 steps X 10 receivers: 0.03
|
82
|
-
- 10 senders X 1000 steps X 10 receivers: 0.01
|
83
|
-
- 100 senders X 100 steps X 10 receivers: 0.02
|
84
|
-
- 1 senders X 1000 steps X 100 receivers: 0.00
|
85
|
-
- 10 senders X 100 steps X 100 receivers: 0.02
|
86
|
-
- 100 senders X 10 steps X 100 receivers: 0.03
|
data/bench/aug7.bench
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
alg-state:
|
2
|
-
- 0 comps X 1000 steps X 0 non-alg: 0.01
|
3
|
-
- 10 comps X 1000 steps X 0 non-alg: 0.00
|
4
|
-
- 100 comps X 1000 steps X 0 non-alg: 0.02
|
5
|
-
- 1000 comps X 1000 steps X 0 non-alg: 0.08
|
6
|
-
- 10000 comps X 1000 steps X 0 non-alg: 3.95
|
7
|
-
algebraic:
|
8
|
-
- 1 comps X 1000000 steps: 2.60
|
9
|
-
- 10 comps X 100000 steps: 0.62
|
10
|
-
- 100 comps X 10000 steps: 0.47
|
11
|
-
- 1000 comps X 1000 steps: 0.47
|
12
|
-
- 10000 comps X 100 steps: 1.35
|
13
|
-
- 100000 comps X 10 steps: 1.63
|
14
|
-
connect:
|
15
|
-
- 10 comps X 100000 steps: 0.27
|
16
|
-
- 100 comps X 10000 steps: 0.07
|
17
|
-
- 1000 comps X 1000 steps: 0.09
|
18
|
-
- 10000 comps X 100 steps: 0.41
|
19
|
-
- 100000 comps X 10 steps: 0.96
|
20
|
-
continuous:
|
21
|
-
- 1 comps X 1000000 steps: 2.45
|
22
|
-
- 10 comps X 100000 steps: 0.44
|
23
|
-
- 100 comps X 10000 steps: 0.31
|
24
|
-
- 1000 comps X 1000 steps: 0.32
|
25
|
-
- 10000 comps X 100 steps: 1.12
|
26
|
-
- 100000 comps X 10 steps: 1.40
|
27
|
-
discrete:
|
28
|
-
- 1 comps X 1000000 steps X 0 watchers: 2.56
|
29
|
-
- 10 comps X 100000 steps X 0 watchers: 0.41
|
30
|
-
- 100 comps X 10000 steps X 0 watchers: 0.17
|
31
|
-
- 1000 comps X 1000 steps X 0 watchers: 0.20
|
32
|
-
- 10000 comps X 100 steps X 0 watchers: 0.54
|
33
|
-
- 100000 comps X 10 steps X 0 watchers: 0.69
|
34
|
-
- 1 comps X 1000000 steps X 1 watchers: 3.98
|
35
|
-
- 10 comps X 100000 steps X 1 watchers: 0.73
|
36
|
-
- 100 comps X 10000 steps X 1 watchers: 0.50
|
37
|
-
- 1000 comps X 1000 steps X 1 watchers: 0.59
|
38
|
-
- 10000 comps X 100 steps X 1 watchers: 2.23
|
39
|
-
- 100000 comps X 10 steps X 1 watchers: 2.78
|
40
|
-
- 1 comps X 200000 steps X 5 watchers: 0.87
|
41
|
-
- 10 comps X 20000 steps X 5 watchers: 0.41
|
42
|
-
- 100 comps X 2000 steps X 5 watchers: 0.50
|
43
|
-
- 1000 comps X 200 steps X 5 watchers: 0.90
|
44
|
-
- 10000 comps X 20 steps X 5 watchers: 2.14
|
45
|
-
- 100000 comps X 2 steps X 5 watchers: 3.43
|
46
|
-
euler:
|
47
|
-
- 1 comps X 1000000 steps: 2.43
|
48
|
-
- 10 comps X 100000 steps: 0.36
|
49
|
-
- 100 comps X 10000 steps: 0.21
|
50
|
-
- 1000 comps X 1000 steps: 0.23
|
51
|
-
- 10000 comps X 100 steps: 0.92
|
52
|
-
- 100000 comps X 10 steps: 1.17
|
53
|
-
formula:
|
54
|
-
- 1 comps X 100000 steps: 0.35
|
55
|
-
- 10 comps X 10000 steps: 0.13
|
56
|
-
- 100 comps X 1000 steps: 0.12
|
57
|
-
- 1000 comps X 100 steps: 0.12
|
58
|
-
- 10000 comps X 10 steps: 0.20
|
59
|
-
half-strict:
|
60
|
-
- 10 comps X 100000 steps: 3.93
|
61
|
-
- 100 comps X 10000 steps: 1.29
|
62
|
-
- 1000 comps X 1000 steps: 1.07
|
63
|
-
- 10000 comps X 100 steps: 1.92
|
64
|
-
- 100000 comps X 10 steps: 3.33
|
65
|
-
inertness:
|
66
|
-
- 0 comps X 10000 steps X 0 non-inert: 0.02
|
67
|
-
- 1000 comps X 10000 steps X 0 non-inert: 0.40
|
68
|
-
- 0 comps X 10000 steps X 1 non-inert: 0.17
|
69
|
-
- 1000 comps X 10000 steps X 1 non-inert: 0.50
|
70
|
-
linked-flows:
|
71
|
-
- 1 comps X 1000000 steps: 2.73
|
72
|
-
- 10 comps X 100000 steps: 0.58
|
73
|
-
- 100 comps X 10000 steps: 0.56
|
74
|
-
- 1000 comps X 1000 steps: 0.56
|
75
|
-
- 10000 comps X 100 steps: 2.74
|
76
|
-
- 100000 comps X 10 steps: 3.25
|
77
|
-
queues:
|
78
|
-
- 1 senders X 100000 steps X 1 receivers: 0.31
|
79
|
-
- 10 senders X 10000 steps X 1 receivers: 0.06
|
80
|
-
- 100 senders X 1000 steps X 1 receivers: 0.03
|
81
|
-
- 1 senders X 10000 steps X 10 receivers: 0.05
|
82
|
-
- 10 senders X 1000 steps X 10 receivers: 0.01
|
83
|
-
- 100 senders X 100 steps X 10 receivers: 0.02
|
84
|
-
- 1 senders X 1000 steps X 100 receivers: 0.01
|
85
|
-
- 10 senders X 100 steps X 100 receivers: 0.02
|
86
|
-
- 100 senders X 10 steps X 100 receivers: 0.03
|
data/bench/prof.html
DELETED
File without changes
|
data/examples/robots/README
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
= Robots
|
2
|
-
|
3
|
-
An example covering some of the basic language features plus some techniques for interactive simulation and for animating simulation output.
|
4
|
-
|
5
|
-
To run the example:
|
6
|
-
|
7
|
-
ruby robots.rb
|
8
|
-
|
9
|
-
Press ^C to break into a command shell, and then ^D to continue the simulation run. The "help" command in the shell shows you the commands beyond the basic irb.
|
10
|
-
|
11
|
-
Use -h from the command line to see the switches.
|
12
|
-
|
13
|
-
To change the setup of the world, edit robots.rb. You can add and move robots and missles.
|
14
|
-
|
15
|
-
You can also move the objects interactively in the Tk visualization.
|
16
|
-
|
17
|
-
Currently, the robots move around and the missles track and hit them.
|
18
|
-
|
19
|
-
= To do
|
20
|
-
|
21
|
-
== robots physics
|
22
|
-
|
23
|
-
- collision detection and effect on robot health
|
24
|
-
|
25
|
-
- walls and obstacles
|
26
|
-
|
27
|
-
== robot control
|
28
|
-
|
29
|
-
- command language to evade attackers and launch missiles based on radar
|
30
|
-
|
31
|
-
- maybe similar to RoboTalk (from RoboWar)
|
32
|
-
|
33
|
-
- multirobot coordination using comm channels
|
34
|
-
|
35
|
-
== game mechanics
|
36
|
-
|
37
|
-
- robot shop
|
38
|
-
|
39
|
-
- tournaments
|
40
|
-
|
41
|
-
== dev tools
|
42
|
-
|
43
|
-
- debugger
|
44
|
-
|
45
|
-
- plotter
|
46
|
-
|
47
|
-
== visualization
|
48
|
-
|
49
|
-
- for each sensor, show nearest robot by drawing arrow
|
@@ -1,129 +0,0 @@
|
|
1
|
-
#include "ruby.h"
|
2
|
-
#include "rand.h"
|
3
|
-
|
4
|
-
#ifndef min
|
5
|
-
# define min(a,b) (((a)<(b)) ? (a) : (b))
|
6
|
-
#endif /* min */
|
7
|
-
|
8
|
-
static VALUE
|
9
|
-
ISAAC_s_allocate(VALUE klass)
|
10
|
-
{
|
11
|
-
randctx *ctx;
|
12
|
-
|
13
|
-
return Data_Make_Struct(klass, randctx, NULL, NULL, ctx);
|
14
|
-
}
|
15
|
-
|
16
|
-
/*
|
17
|
-
* Seed the generator with an array of up to ISAAC::RANDSIZ integers in the
|
18
|
-
* range 0..2**32-1. More entries are ignored. Missing entries are treated
|
19
|
-
* as 0. Returns +nil+.
|
20
|
-
*/
|
21
|
-
static VALUE
|
22
|
-
ISAAC_srand(VALUE self, VALUE ary)
|
23
|
-
{
|
24
|
-
int i;
|
25
|
-
randctx *ctx;
|
26
|
-
|
27
|
-
Check_Type(ary, T_ARRAY);
|
28
|
-
|
29
|
-
Data_Get_Struct(self, randctx, ctx);
|
30
|
-
|
31
|
-
MEMZERO(ctx, randctx, 1);
|
32
|
-
for (i=min(RANDSIZ, RARRAY_LEN(ary))-1; i>=0; i--) {
|
33
|
-
ctx->randrsl[i] = NUM2UINT(RARRAY_PTR(ary)[i]);
|
34
|
-
}
|
35
|
-
rs_isaac_init(ctx, 1);
|
36
|
-
|
37
|
-
return Qnil;
|
38
|
-
}
|
39
|
-
|
40
|
-
/*
|
41
|
-
* Return a random integer in the range 0..2**32-1.
|
42
|
-
*/
|
43
|
-
static VALUE
|
44
|
-
ISAAC_rand32(VALUE self)
|
45
|
-
{
|
46
|
-
randctx *ctx;
|
47
|
-
|
48
|
-
Data_Get_Struct(self, randctx, ctx);
|
49
|
-
|
50
|
-
if (!ctx->randcnt--) {
|
51
|
-
rs_isaac_rand(ctx);
|
52
|
-
ctx->randcnt=RANDSIZ-1;
|
53
|
-
}
|
54
|
-
|
55
|
-
return UINT2NUM(ctx->randrsl[ctx->randcnt]);
|
56
|
-
}
|
57
|
-
|
58
|
-
/*
|
59
|
-
* Return a random float in the range 0..1.
|
60
|
-
*/
|
61
|
-
static VALUE
|
62
|
-
ISAAC_rand(VALUE self)
|
63
|
-
{
|
64
|
-
randctx *ctx;
|
65
|
-
|
66
|
-
Data_Get_Struct(self, randctx, ctx);
|
67
|
-
|
68
|
-
if (!ctx->randcnt--) {
|
69
|
-
rs_isaac_rand(ctx);
|
70
|
-
ctx->randcnt=RANDSIZ-1;
|
71
|
-
}
|
72
|
-
|
73
|
-
return rb_float_new(ctx->randrsl[ctx->randcnt] / 4294967295.0);
|
74
|
-
}
|
75
|
-
|
76
|
-
/* :nodoc: */
|
77
|
-
static VALUE
|
78
|
-
ISAAC_marshal_dump(VALUE self)
|
79
|
-
{
|
80
|
-
randctx *ctx;
|
81
|
-
int i;
|
82
|
-
int ary_size = sizeof(randctx)/sizeof(ub4);
|
83
|
-
VALUE ary;
|
84
|
-
|
85
|
-
Data_Get_Struct(self, randctx, ctx);
|
86
|
-
|
87
|
-
ary = rb_ary_new2(ary_size);
|
88
|
-
for (i = 0; i < ary_size; i++) {
|
89
|
-
rb_ary_push(ary, UINT2NUM(((ub4 *)ctx)[i]));
|
90
|
-
}
|
91
|
-
|
92
|
-
return ary;
|
93
|
-
}
|
94
|
-
|
95
|
-
/* :nodoc: */
|
96
|
-
static VALUE
|
97
|
-
ISAAC_marshal_load(VALUE self, VALUE ary)
|
98
|
-
{
|
99
|
-
randctx *ctx;
|
100
|
-
int i;
|
101
|
-
int ary_size = sizeof(randctx)/sizeof(ub4);
|
102
|
-
|
103
|
-
Data_Get_Struct(self, randctx, ctx);
|
104
|
-
|
105
|
-
if (RARRAY_LEN(ary) != ary_size)
|
106
|
-
rb_raise(rb_eArgError, "bad length in loaded ISAAC data");
|
107
|
-
|
108
|
-
for (i = 0; i < ary_size; i++) {
|
109
|
-
((ub4 *)ctx)[i] = NUM2UINT(RARRAY_PTR(ary)[i]);
|
110
|
-
}
|
111
|
-
|
112
|
-
return self;
|
113
|
-
}
|
114
|
-
|
115
|
-
void
|
116
|
-
Init_isaac()
|
117
|
-
{
|
118
|
-
VALUE ISAAC;
|
119
|
-
|
120
|
-
ISAAC = rb_define_class("ISAAC", rb_cObject);
|
121
|
-
rb_define_alloc_func(ISAAC, ISAAC_s_allocate);
|
122
|
-
rb_define_method(ISAAC, "srand", ISAAC_srand, 1);
|
123
|
-
rb_define_method(ISAAC, "rand32", ISAAC_rand32, 0);
|
124
|
-
rb_define_method(ISAAC, "rand", ISAAC_rand, 0);
|
125
|
-
rb_define_method(ISAAC, "marshal_dump", ISAAC_marshal_dump, 0);
|
126
|
-
rb_define_method(ISAAC, "marshal_load", ISAAC_marshal_load, 1);
|
127
|
-
|
128
|
-
rb_const_set(ISAAC, rb_intern("RANDSIZ"), UINT2NUM(RANDSIZ));
|
129
|
-
}
|