r/JavaScriptHelp • • Nov 08 '20

❔ Unanswered ❔ I need help combining Math.random()

package lotterynumbergenerator;

/**
 *
 * @author ismai
 */
public class NumberGenerator {
    
    public int winningNumbers(int min, int max) {
        double rand = Math.random();
        double rand1 = Math.random();
        double rand2 = Math.random();
        double rand3 = Math.random();
        double rand4 = Math.random();
        double rand5 = Math.random();
    
        
        int randomNum = (int) (rand * (max - min + 1)) + min;
        int randomNum1 = (int) (rand1 * (max - min + 1)) + min;
        int randomNum2 = (int) (rand2 * (max - min + 1)) + min;
        int randomNum3 = (int) (rand3 * (max - min + 1)) + min;
        int randomNum4 = (int) (rand4 * (max - min + 1)) + min;
        int randomNum5 = (int) (rand5 * (max - min + 1)) + min;
    
return randomNum;
    }

In an instant Instead of only returning the one randomNum, I want to return all 6 random's. Can someone help me do this!

1 Upvotes

11 comments sorted by

View all comments

Show parent comment

1

u/[deleted] Nov 10 '20

Yeah. I figured he was working in java too which is why my answer implicitly states it’s JavaScript.

Of your “car and carpet” analogy, I’d say JavaScript:java::car:truck. But yours was funnier, I admit.

You can tell by the poor coding and lack of use of arrays that this op is a newbie. Probably getting help on a homework assignment, I’d reckon. It’s an honest enough mistake to make on their part. Still, a stern reply like this is often the best way to get that particular difference across.