Flash Games

 FAQ   Search   Members   Groups   Register  User Control Panel      Login 

Your time now:
Sat Nov 21, 2009 10:57 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 1 post ]  Bookmark and Share
Author Message
 Post subject: How to Generate Unique Random Numbers?
PostPosted: Mon Sep 22, 2008 7:49 am 
Offline

Joined: Thu Sep 11, 2008 7:34 am
Posts: 4
Code:


import com.sun.crypto.provider.RSACipher;
import java.util.Random;

public class RandomRange {

    static  int START = 1;
    static int END;
   static  Random random = new Random();
 
    private static void showRandomInteger(int aStart, int aEnd, Random aRandom){
            if ( aStart > aEnd ) {
                throw new IllegalArgumentException("Start cannot exceed End.");
            }
            //get the range, casting to long to avoid overflow problems
            long range = (long)aEnd - (long)aStart + 1;
            // compute a fraction of the range, 0 <= frac < range
            long fraction = (long)(range * aRandom.nextDouble());
            int randomNumber =  (int)(fraction + aStart);                     
            //  System.out.println("Hi this is from senthil == >"+ j );
            log("Generated : " + randomNumber);
    }
   
    private static void log(String aMessage){
        System.out.println(aMessage);
    }   
   
    public static void main(String aArgs[]){
        int countrec = 9;
        log("Generating random integers in the range "+START+"...." + countrec);
        END = countrec - 1;
      for (int idx = START; idx <= 5; ++idx){
            showRandomInteger(START, END, random);
        }
        log("Done.");
       
       
    }
}





Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group - Flash Games - TNX Invitation Code - TNX Review


Webmaster - Excruciating - Johnathan - Kotik - Ash - Tomi - rangana - Phate - dflynn - Medley