×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    5

    Question How to write a Random() method?

    Hi there,
    i am using Nokia_7210_MIDP_SDK_v1_0 which doesn't provide the Math.random() method,but i am now writing a Tetrics game MIDlet and need to generate random square.
    How can I write my own random() method?Can anyboy help?
    Thank you in advance!

  2. #2
    Regular Contributor
    Join Date
    Aug 2003
    Location
    uk
    Posts
    232
    I think you will find it does .. but not in Math.

    Code:
    import  java.util.Random;
    
    Random random = new Random();
    
    // --------------------------------------------------------------------- //
    public static int rand(int scale)
    {
    	try
    	{
    		return (random.nextInt() << 1 >>> 1) % scale;
    	}
    	catch (Exception e)
    	{
    		return(0);
    	}
    }
    // --------------------------------------------------------------------- //

  3. #3
    Registered User
    Join Date
    Feb 2005
    Posts
    5
    oh,i forgot that part!
    Thank you so much!

  4. #4
    Regular Contributor
    Join Date
    Aug 2003
    Location
    uk
    Posts
    232
    no worries.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×