Hello guys, Hope ur listening. I need my code to generate 6 random numbers for each line, instead of just 1. Furthermore, there should be no duplicate numbers on any particular line. So far I have gotten this code to print only a single number per line, so I need to add 5 more numbers to each line. Thanks in advance.import java.util.List;
import java.util.ArrayList;
import java.util.Collections;

public class Lottotest
{

private static List lottoBarrel = new ArrayList(45);

private static void initializeBarrel()
{
for (int i = 1; i < 45; i++)
{
lottoBarrel.add(new Integer(i));
}
}

private static void printBarrel(String message)
{
System.out.println(message + "\n");
for (int i = 1; i <= 6; i++)
{
System.out.println("number " + i +" = " + lottoBarrel.get(i));
}
System.out.println("============");
}

public static void main(String[] args)
{
initializeBarrel();
Collections.shuffle(lottoBarrel);
printBarrel("Barrel rolled:");
}

U should use java.util.Random or Math.random() to generate random numbers.

1) you're not generating any random numbers at all. You're drawing your numbers from a collection of fixed numbers which has been ordered using a random sequence. That's not the same thing (but it's likely you want in this case).
2) you're explicitly printing a line terminator after every number when you call println, which is why you see your non-random numbers each on a line of their own.
3) you're not using code tags.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.