File tree Expand file tree Collapse file tree 1 file changed +7
-22
lines changed Expand file tree Collapse file tree 1 file changed +7
-22
lines changed Original file line number Diff line number Diff line change @@ -28,36 +28,21 @@ class Rand
28
28
@seed = seed
29
29
30
30
# return a random integer 0 <= n < @modulo
31
- randn:
31
+ randn: ->
32
32
# new_seed = (a * seed + c) % m
33
33
@seed = (@multiplier*@seed + @offset) % @modulo
34
34
35
35
# return a random float 0 <= f < 1.0
36
- rand : ->
36
+ randf : ->
37
37
this.randn() / @modulo
38
38
39
39
# return a random int 0 <= f < n
40
- randi : (n) ->
41
- Math.floor(this.rand () * n)
40
+ rand : (n) ->
41
+ Math.floor(this.randf () * n)
42
42
43
- r = new Rand 0
44
- r.randn().toString(16)
45
- # => "3c6ef35f"
46
-
47
- r.randn().toString(16)
48
- # => "47502932"
49
-
50
- r.randn().toString(16)
51
- # => "d1ccf6e9"
52
-
53
- r.randn().toString(16)
54
- # => "aaf95334"
55
-
56
- r.randn().toString(16)
57
- # => "6252e503"
58
-
59
- r.randn().toString(16)
60
- # => "9f2ec686"
43
+ # return a random int min <= f < max
44
+ rand2: (min, max) ->
45
+ min + this.rand(max-min)
61
46
{% endhighlight %}
62
47
63
48
h2. Discussion
You can’t perform that action at this time.
0 commit comments