If you have a problem or need to report a bug please email : support@dsprobotics.com
There are 3 sections to this support area:
DOWNLOADS: access to product manuals, support files and drivers
HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects
USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here
NEW REGISTRATIONS - please contact us if you wish to register on the forum
Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright
Ruby string randomizer-total random?
4 posts
• Page 1 of 1
Ruby string randomizer-total random?
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?
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?
-
kortezzzz - Posts: 763
- Joined: Tue Mar 19, 2013 4:21 pm
Re: Ruby string randomizer-total random?
yes thats easy:
Array.new(10) { rand(-1.0...1.0) }
it creates 10 different numbers from -1 to 1
Array.new(10) { rand(-1.0...1.0) }
it creates 10 different numbers from -1 to 1
- adamszabo
- Posts: 667
- Joined: Sun Jul 11, 2010 7:21 am
Re: Ruby string randomizer-total random?
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
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
"There lies the dog buried" (German saying translated literally)
- tulamide
- Posts: 2714
- Joined: Sat Jun 21, 2014 2:48 pm
- Location: Germany
Re: Ruby string randomizer-total random?
Adam & tulamide, Thanks for the help, guys.
Would be really interesting to see flowstone made casino games line for sure
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
Anyway, here is the full code formulation for those who have no idea how to add your solution into the code:
The ruby module should have 1 trigger input and one array output. Once you send the trigger, the output fires the random array
Would be really interesting to see flowstone made casino games line for sure
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
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
-
kortezzzz - Posts: 763
- Joined: Tue Mar 19, 2013 4:21 pm
4 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 44 guests