Skip to content

Commit cf0adc1

Browse files
ethancrawfordsamaaron
authored andcommitted
Docs - Fix rand_look and rand_i_look examples
Previously, the behaviour of the last two lines in the affected examples was reversed. (Ie, rand and rand_i would *not* in fact print new random numbers, but the same ones as the preceding calls to rand_look and rand_i_look, since rand_look and rand_i_look 'look ahead' at what the calls to rand and rand_i would produce, and the subsequent calls to rand and rand_i will advance the random stream, meaning that calls to rand_look and rand_i_look after this will look at a *new* random number. Fixes #2693
1 parent edf3246 commit cf0adc1

File tree

1 file changed

+16
-12
lines changed
  • app/server/ruby/lib/sonicpi/lang

1 file changed

+16
-12
lines changed

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

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3132,14 +3132,16 @@ def rand_look(*args)
31323132
31333133
Does not consume a random value from the stream. Therefore, multiple sequential calls to `rand_look` will all return the same value.",
31343134
examples: ["
3135-
print rand_look(0.5) #=> will print a number like 0.375030517578125 to the output pane",
3135+
print rand_look(0.5) # will print a number like 0.375030517578125 to the output pane",
31363136

31373137
"
3138-
print rand_look(0.5) #=> will print a number like 0.375030517578125 to the output pane
3139-
print rand_look(0.5) #=> will print the same number again
3140-
print rand_look(0.5) #=> will print the same number again
3141-
print rand(0.5) #=> will print a different random number
3142-
print rand_look(0.5) #=> will print the same number as the previous line again."
3138+
print rand_look(0.5) # will print a number like 0.375030517578125 to the output pane
3139+
print rand_look(0.5) # will print the same number again
3140+
print rand_look(0.5) # will print the same number again
3141+
print rand(0.5) # will still print the same number again
3142+
# (this is the number rand_look was 'looking ahead' at)
3143+
# the number is now consumed
3144+
print rand_look(0.5) # will print a new number like 0.3669586181640625 to the output pane"
31433145
]
31443146

31453147

@@ -3160,14 +3162,16 @@ def rand_i_look(*args)
31603162
31613163
Does not consume a random value from the stream. Therefore, multiple sequential calls to `rand_i_look` will all return the same value.",
31623164
examples: ["
3163-
print rand_i_look(5) #=> will print either 0, 1, 2, 3, or 4 to the output pane",
3165+
print rand_i_look(5) # will print either 0, 1, 2, 3, or 4 to the output pane",
31643166

31653167
"
3166-
print rand_i_look(5) #=> will print either 0, 1, 2, 3, or 4 to the output pane
3167-
print rand_i_look(5) #=> will print the same number again
3168-
print rand_i_look(5) #=> will print the same number again
3169-
print rand_i(5) #=> will print either 0, 1, 2, 3, or 4 to the output pane
3170-
print rand_i_look(5) #=> will print the same number as the previous statement"
3168+
print rand_i_look(5) # will print either 0, 1, 2, 3, or 4 to the output pane
3169+
print rand_i_look(5) # will print the same number again
3170+
print rand_i_look(5) # will print the same number again
3171+
print rand_i(5) # will still print the same number again
3172+
# (this is the number rand_i_look was 'looking ahead' at)
3173+
# the number is now consumed
3174+
print rand_i_look(5) # will print either 0, 1, 2, 3, or 4 to the output pane"
31713175
]
31723176

31733177

0 commit comments

Comments
 (0)