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

save random numbers

 
s dont
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
below is the coding for random numbers

public class Random {public static void main(String[] args) {java.util.Random rand = new java.util.Random();for (int i = 0; i < 20; i++) {System.out.println(rand.nextInt(10));}}}

how do i save the random numbers???
 
John Smith
Ranch Hand
Posts: 2937
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how do i save the random numbers???
Depends where you want to save them. Database? Memory? Text File? Serialized data?
 
Tom Blough
Ranch Hand
Posts: 263
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you seed the generator with a known value, you can re-generate the SAME string of "random" numbers any time by just reseeding the generator with the same number again. That way, you do not need to save the generated numbers in the first place.
[ October 27, 2003: Message edited by: Tom Blough ]
 
William Barnes
Ranch Hand
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I sure hope that you don't actually write your code like that, all on one line.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic