6 Replies - 275 Views - Last Post: 16 September 2012 - 03:07 PM Rate Topic: -----

#1 2145  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 24-August 12

Random number generator

Posted 02 September 2012 - 10:37 AM

How can i generate any number randomly using java?
Is This A Good Question/Topic? 0
  • +

Replies To: Random number generator

#2 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2833
  • View blog
  • Posts: 12,000
  • Joined: 20-September 08

Re: Random number generator

Posted 02 September 2012 - 10:47 AM

http://technojeeves....-value-in-range
http://technojeeves....-random-numbers
Was This Post Helpful? 0
  • +
  • -

#3 Miikalsen  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 85
  • Joined: 29-December 11

Re: Random number generator

Posted 02 September 2012 - 11:57 AM

Import java.util.Random;



int a = new Random();



Simple as that.
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8347
  • View blog
  • Posts: 31,913
  • Joined: 06-March 08

Re: Random number generator

Posted 02 September 2012 - 12:01 PM

View PostMiikalsen, on 02 September 2012 - 02:57 PM, said:

Import java.util.Random;

int a = new Random();


Simple as that.

Not really

int a = new Random(); won't even compile

Random ran = new Random();
int x = ran.nextInt();

will work though
Was This Post Helpful? 0
  • +
  • -

#5 2145  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 24-August 12

Re: Random number generator

Posted 16 September 2012 - 10:37 AM

View Postpbl, on 02 September 2012 - 12:01 PM, said:

View PostMiikalsen, on 02 September 2012 - 02:57 PM, said:

Import java.util.Random;

int a = new Random();


Simple as that.

Not really

int a = new Random(); won't even compile

Random ran = new Random();
int x = ran.nextInt();

will work though

But the problem is i want to generate a number in ceratin range.
Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8347
  • View blog
  • Posts: 31,913
  • Joined: 06-March 08

Re: Random number generator

Posted 16 September 2012 - 10:46 AM

int x = ran.nextInt(10);

will generate a number between 0 and 9

http://docs.oracle.c...ml#nextInt(int)
Was This Post Helpful? 0
  • +
  • -

#7 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2833
  • View blog
  • Posts: 12,000
  • Joined: 20-September 08

Re: Random number generator

Posted 16 September 2012 - 03:07 PM

Quote

But the problem is i want to generate a number in ceratin range.

http://technojeeves....-value-in-range
Was This Post Helpful? -1
  • +
  • -

Page 1 of 1