•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 456,610 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,507 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 2351 | Replies: 2
![]() |
•
•
Join Date: Oct 2007
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
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:");
}
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:");
}
•
•
Join Date: Nov 2004
Location: Netherlands
Posts: 5,752
Reputation:
Rep Power: 19
Solved Threads: 200
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.
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.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
![]() |
•
•
•
•
•
•
•
•
DaniWeb Java Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
access activation api blogger blogging blogs code com combo dani daniweb data debugging development dreamweaver dropdownlist gdata google gpl html innovation java key linux microsoft microsoft sdk for java microsystems module net news open openbsd platform product programming reuse rss serial software source sun tags vista web wysiwyg xml
- Random number generator's (C++)
- Random number Generation (C)
- Random number generator (Java)
- Random number generator (Java)
- Getting a non-random number? (C++)
- Need to know how to create a database that will generate a random number (Database Design)
- Random Number help (Java)
- Can N E 1 Help!!!! -- Need sample Java code (Java)
- Help with random number gen (C++)
Other Threads in the Java Forum
- Previous Thread: images not displaying in JSP pages!
- Next Thread: Reversing a string using recursion



Linear Mode