generate random number of string with java

Posted on 2009-05-12
Last Modified: 2013-11-23
i want to generate around 10000 lines of random strings and input it to file in java. Please tell me how to do it. Also tell me how to reach to the end of this file after generating the lines. Also tell me how to find the length of the file and the number of lines in this file. Please do not use any system commands or tail command
Question by:SunScreenCert
1 Comment

Accepted Solution

sundar62 earned 125 total points
ID: 24371689
Please find the code snippet below to generate the random number. you can get the number of lines of the file from the attached link -

You may modify the code accordingly..


public class GUID {

   private static SecureRandom s_secureRandom = new SecureRandom();

   public static void main(String[] args) throws Exception {

	   File file = new File("write.txt");

	   PrintWriter output = new PrintWriter(new BufferedWriter(new FileWriter(file)));


	   for (int i = 0; i < 10000 ;i++ )



	   System.out.println("Your file has been written");





    * generate guid from time,addr,hash and rand


   public static String generate() {

      StringBuilder stringBuilder = new StringBuilder();

      int time = (int) System.currentTimeMillis();

      int rand = s_secureRandom.nextInt();


      return stringBuilder.toString();



    * get int as 8-char string


   private static String hexFormat(int data) {

      StringBuilder stringBuilder = new StringBuilder();



      return stringBuilder.substring(stringBuilder.length() - 8);



Open in new window


Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
sites similar to codingbat to improve coding hanson skills 3 41
Java Jpanels and Jframe 8 28
servlet example issue 6 32
use lov values 2 36
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now