Random output from array

Capitán

kind of a big deal
Veteran
Joined
Jul 9, 2013
Messages
572
Reaction score
145
First Language
Engilsh
Primarily Uses
RMMV
lets say I have this array:

My_Array = ["foo", "bar"]I know in Ruby 1.9.3 you could just do

My_String = My_Array.samplebut I don't think it works in this case

I could just set it up with variables like

num = rand(100)if num < 50 My_String = "foo"endbut that would be too tedious because I want to create a long array.

So how would I go about getting a random out put from an array?
 
Last edited by a moderator:

Hudell

Dog Lord
Veteran
Joined
Oct 2, 2014
Messages
3,545
Reaction score
3,715
First Language
Java's Crypt
Primarily Uses
RMMZ
Why wouldn't My_Array.sample work?

I've always used it.
 

♥SOURCE♥

Too sexy for your party.
Veteran
Joined
Mar 14, 2012
Messages
693
Reaction score
411
Primarily Uses
Yep, .sample works in 1.9.2 too. Are you getting any kind of error message? Maybe the problem lies somewhere else.
 

Capitán

kind of a big deal
Veteran
Joined
Jul 9, 2013
Messages
572
Reaction score
145
First Language
Engilsh
Primarily Uses
RMMV
Ahhh I see I forgot to close my bracket LOL. I'm sorry for the trouble
 

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,162
Reaction score
822
First Language
Hungarian
Primarily Uses
RMVXA
If you don't want to use the sample way, you can always just do this:

ary = [*random values go here*]select = ary[rand(ary.size)]I never actually used the sample way, mostly because I had some extra conditions I needed to process before the randomization, but it could be useful for a simple randomization with no extra stuffs going on...Btw, why is this topic here? o.o
 
Last edited by a moderator:

Capitán

kind of a big deal
Veteran
Joined
Jul 9, 2013
Messages
572
Reaction score
145
First Language
Engilsh
Primarily Uses
RMMV
Btw, why is this topic here? o.o
Posted here on accident, it was approved, I reported it as soon as I realized but no one has reacted.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,849
Messages
1,016,977
Members
137,563
Latest member
cexojow
Top