Skip to content

Commit 4dcb02d

Browse files
committed
Core - fix rand_look and rand_i_look to honour their arguments
1 parent d01d064 commit 4dcb02d

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ used for Windows.
6565
* Improve error message reported when required ports are not available
6666
at boot.
6767
* Fix issue with calling `control` on a chord group.
68+
* Fix `rand` and `rand_i` to honour their arguments.
6869

6970
<a name="v2.11"></a>
7071

app/server/sonicpi/lib/sonicpi/lang/core.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2346,8 +2346,9 @@ def rand_i(max=2)
23462346

23472347

23482348
def rand_look(*args)
2349-
rand(*args)
2349+
res = rand(*args)
23502350
rand_back
2351+
res
23512352
end
23522353
doc name: :rand_look,
23532354
introduced: Version.new(2,11,0),
@@ -2373,8 +2374,9 @@ def rand_look(*args)
23732374

23742375

23752376
def rand_i_look(*args)
2376-
rand_i(*args)
2377+
res = rand_i(*args)
23772378
rand_back
2379+
res
23782380
end
23792381
doc name: :rand_i_look,
23802382
introduced: Version.new(2,11,0),

app/server/sonicpi/test/lang/core/test_random.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,21 @@ def test_rand_i_only_returns_ints
9797
assert_equal(Fixnum, rand_i(0..10).class)
9898
assert_equal(Fixnum, rand_i(1.5).class)
9999
end
100+
101+
def test_rand_look
102+
rand_reset
103+
assert_equal(rand_look, 0.75006103515625)
104+
105+
rand_reset
106+
assert_equal(rand_look(0.5), 0.375030517578125)
107+
end
108+
109+
def test_rand_i_look
110+
rand_reset
111+
assert_equal(rand_i_look, 1)
112+
113+
rand_reset
114+
assert_equal(rand_i_look(100), 75)
115+
end
100116
end
101117
end

0 commit comments

Comments
 (0)