File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generating a number

 
Tony Evans
Ranch Hand
Posts: 597
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to generate a random number of 11 digits, i am looking for a object that wiill take a number an then generate that number of digits.

Thanks
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12017
24
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I doubt there is such a thing that does what you are asking. You are going to have to write it yourself.

Do you have a specific question?
 
Tony Evans
Ranch Hand
Posts: 597
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup i want to generate random number, i know there are random number generators out there, i was just wondering of there is one that will generate numbers specic to a size given, so say give it a parameter 8 it will generate 8 numbers.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's not exactly a method like you describe in Java's standard API. However, it's not hard to do this, using java.util.Random.

If you want a random number with 8 digits, then basically what you want is a random number between 10,000,000 and 99,999,999.
 
Tony Evans
Ranch Hand
Posts: 597
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks that put me in the right direction

 
Campbell Ritchie
Sheriff
Pie
Posts: 47244
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That will not quite work. If you obtain a number < 1000000, you will not put 6 digits into your string builder.
And why are you using substring when there is a StringBuilder method which will reduce the output to n characters before you return it as a String?
And did you ever obtain the same printout ten times?
 
Winston Gutkowski
Bartender
Pie
Posts: 9472
50
Eclipse IDE Hibernate Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tony Evans wrote:Thanks that put me in the right direction

As Campbell said, that won't work.

Possibly closer is Jesper's suggestion; but best of all: back up and tell us exactly what it is you want to do, because right now we're floundering around in the dark. I'm still not sure if you want 8 numbers, or an 11-digit number (or indeed, what an "11-digit number" means to you), or both, or some combination of either.

Winston
 
Campbell Ritchie
Sheriff
Pie
Posts: 47244
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Earlier, I wrote:. . . If you obtain a number < 1000000, you will not put 6 digits into your string builder. . . .
Sorry. For 1000000 read 100000.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic