|
-
Random numbers
I'm doing a java program using random numbers.
I would like to avoid that each generated number, besides unique, is different from its index in array - for instance, the first number in array is not number 1, the second is not number 2, the third not number 3, and so one.
Can someone help ?
Thatīs my relevant code :
boolean isRepeated = false;
int [] rNums = new int [t1];
for (int x = 0 ; x < t1 ; x++)
{
do
{
isRepeated = false;
rNums [x] = (int) ((Math.random () * t1) + 1);
for (int y = 0 ; y < x ; y++)
{
if (rNums [x] == rNums [y])
{
isRepeated = true;
break;
}
}
}
while (isRepeated);
Similar Threads
-
Replies: 3
Last Post: 10-12-2005, 01:35 AM
-
By Suze in forum VB Classic
Replies: 2
Last Post: 05-10-2005, 03:41 PM
-
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