How could i draw 2 random words without them drawing the same word as each other? | SoloLearn: Learn to code for FREE!

0

How could i draw 2 random words without them drawing the same word as each other?

12/17/2017 7:40:26 PM

jalen

5 Answers

New Answer

+7

An idea https://code.sololearn.com/cPP0ZynlhIn4/?ref=app

+8

To stop consecutive repeating strings you can store the strings in a data structure, then to get an index, reduce the range of random values and use modulus on the random value for indexes. Assume strings is an array of Strings. It's length is given by strings.length. We can then do rand % strings.length to get indexes to pick words from the array strings.

+1

@ ace could you give a small example of it, I'm kind of confused?

+1

@ ace thanks this is way more practical than my way of just a bunch of "if" and "else if" statements.

0

comparison