Page 1 of 1

Ruby string randomizer-total random?

Posted: Thu Sep 22, 2016 7:58 pm
by kortezzzz
Hi,

Inspired by last randimizing code examples that already came up at forum, just wondered how far can ruby go with that feature. Can it, for instance, randomize fixed amount of values between 2 given points independently?

I mean can I ask ruby to give me 40 random float values array from (-1) to 1 each time I send a trigger?

Re: Ruby string randomizer-total random?

Posted: Thu Sep 22, 2016 8:14 pm
by adamszabo
yes thats easy:

Array.new(10) { rand(-1.0...1.0) }

it creates 10 different numbers from -1 to 1

Re: Ruby string randomizer-total random?

Posted: Thu Sep 22, 2016 9:39 pm
by tulamide
Arrays are great. Sometimes you just want the array itself in random order (for example when doing a card game). Just call

Array.shuffle

to do so. In the case that Adam described, it would mean you'd keep the once set random numbers, but in random order each time you call .shuffle

Re: Ruby string randomizer-total random?

Posted: Thu Sep 22, 2016 10:55 pm
by kortezzzz
Adam & tulamide, Thanks for the help, guys.

Would be really interesting to see flowstone made casino games line for sure 8-)
If FS just had solid solution for net communication, we could develop some cards, roulette or any gambling games, but I'll try to think about some more interesting uses for randomizing :D

Anyway, here is the full code formulation for those who have no idea how to add your solution into the code:

Code: Select all

def init

end

def event i,v
    @array=Array.new(67) { rand(-1.0...1.0) }
 
     if i == 0 then
       @randarray = @array.shuffle
       output 0,@randarray
    end

 

end


The ruby module should have 1 trigger input and one array output. Once you send the trigger, the output fires the random array ;)