|
-
Random Numbers on button
Hi,
I was wondering how do i go about generating unique random numbers?
ie
i want to generate numbers between 0-9 randomly. I dont want to repeat the numbers.Then that no: should display on the buttons.ie there are 9 buttons. first randomly generated number should display on the first button & 2nd no: should display on 2nd button. & so on for example I have the numbers 9371482065 then 9 should display on the first button ,3 should display on 2nd button ....
But the following code i'm having is repeating some numbers...can any one help me in solving...please.....
code::::
Random rgen = new Random(); // Random number generator
int[] cards = new int[10];
// --- Initialize the array to the ints 0-51
for (int i=0; i<10; i++) {
cards[i] = i;
}
// --- Shuffle by exchanging each element randomly
for (int i=0; i<10; i++) {
int randomPosition = rgen.nextInt(10);
System.out.println(" randomPosition " + randomPosition);
int temp = cards[i];
System.out.println(" temp" + temp);
cards[i] = cards[randomPosition];
cards[randomPosition] = temp;
System.out.println(" Random Number" + cards[randomPosition]);
}
Similar Threads
-
By Suze in forum VB Classic
Replies: 2
Last Post: 05-10-2005, 03:41 PM
-
By DrunkinP in forum Java
Replies: 0
Last Post: 03-31-2005, 09:36 AM
-
Replies: 3
Last Post: 05-14-2002, 08:04 PM
-
Replies: 2
Last Post: 04-30-2001, 03:08 PM
-
By Jeff Condon in forum Security
Replies: 0
Last Post: 08-25-2000, 07:54 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks