Skip to content

Commit 7cbc120

Browse files
ethancrawfordsamaaron
authored andcommitted
Lang - add fn to get current random source
This brings the random source functions into line with other similar use_/with_* functions by including a corresponding current_* function to get the current random number source.
1 parent 8695cf3 commit 7cbc120

File tree

1 file changed

+28
-0
lines changed
  • app/server/ruby/lib/sonicpi/lang

1 file changed

+28
-0
lines changed

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3871,6 +3871,34 @@ def current_random_seed
38713871
puts rand #=> 0.24249267578125
38723872
"]
38733873

3874+
def current_random_source
3875+
SonicPi::Core::SPRand.get_random_number_distribution
3876+
end
3877+
doc name: :current_random_source,
3878+
introduced: Version.new(3,3,2),
3879+
summary: "Get current random source",
3880+
doc: "Returns the source of the current random number generator (what kind of noise is generating the random numbers).
3881+
3882+
This can be set via the fns `use_random_source` and `with_random_source`. Each source will provide a different pattern of random numbers.",
3883+
args: [],
3884+
opts: nil,
3885+
accepts_block: false,
3886+
examples: ["
3887+
puts current_random_source # Print out the current random source",
3888+
"
3889+
use_random_source :white # Use white noise as the distribution (default)
3890+
puts rand # => 0.75006103515625
3891+
puts rand # => 0.733917236328125
3892+
a = current_random_source # Grab the current random number source (:white)
3893+
use_random_source :perlin # Use perlin noise as the distribution
3894+
puts rand # => 0.58526611328125
3895+
puts rand # => 0.597015380859375
3896+
use_random_source a # Restore the previous random number source (:white)
3897+
# The numbers will again be generated from a white noise distribution
3898+
puts rand # => 0.10821533203125
3899+
puts rand # => 0.54010009765625
3900+
"]
3901+
38743902

38753903
def current_bpm
38763904
__current_bpm

0 commit comments

Comments
 (0)