Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

generate a text file with random no of characters

 
Ranch Hand
Posts: 417
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how to generate a text file that contains a random string of letters or characters ?
ie it should be able to control the number of letters in one line and the number of lines in the text file.
please email me a cc at markstone23@yahoo.com
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Very funny.
What have you tried so far?
 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can generate random characters using the Math.random() method.
With it you get a random [0-1] number.You can multiply it by n(the number of letters you have),round it(the method returns a double), and you have an random 0-n number.
Just assing a numeric value for each letter.
-HTH
 
Juanjo Bazan
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
with this method you can generate "words" with the lenght you want:
//the argument n is the number of words you want
//the argument len is the lenght of the words
public String[] generateWords(int n, int len){
String[] words=new String[n];
char[] eachWord=new char[len];
for (int j=0;j<n;j++){
for (int i=0;i<len;i++){
//I assume you have a method convertToLetter where you have assigned a numeric value to each letter, and which receives a 0-1 number and returns a char.
eachWord[i]=convertToLetter(Math.Random());
}
words[j]=new String(eachWord);
}
return words;
}//end of method
-HTH
[ July 12, 2002: Message edited by: Juanjo Bazan ]
[ July 12, 2002: Message edited by: Juanjo Bazan ]
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic