Welcome to Dream.In.Code
Become a Java Expert!

Join 150,194 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,022 people online right now. Registration is fast and FREE... Join Now!




Generate random text

 
Reply to this topicStart new topic

Generate random text

itian
16 Sep, 2008 - 01:18 AM
Post #1

New D.I.C Head
*

Joined: 16 Sep, 2008
Posts: 2

Hii all

I want to generate random text in java
I need your help smile.gif
thank you
User is offlineProfile CardPM
+Quote Post

dineeshd
RE: Generate Random Text
16 Sep, 2008 - 01:31 AM
Post #2

D.I.C Addict
Group Icon

Joined: 30 Jun, 2008
Posts: 579



Thanked: 16 times
Dream Kudos: 575
My Contributions
Need more explanation and post the code you have so far (if you have).
User is offlineProfile CardPM
+Quote Post

itian
RE: Generate Random Text
16 Sep, 2008 - 01:40 AM
Post #3

New D.I.C Head
*

Joined: 16 Sep, 2008
Posts: 2

QUOTE(dineeshd @ 16 Sep, 2008 - 02:31 AM) *

Need more explanation and post the code you have so far (if you have).



thnx for your fasrt reply smile.gif

I already made this method... It works well but sometimes it gives me an exception which is as I remembered " the output must be positive " I think that the code generate negative output ... here is my code

public String generateRandomText() {

final Random random = new Random(System.currentTimeMillis());

byte len = 10;
byte[] buf = new byte[len * 2];
char[] text = new char[len];
int c = 0;
while (c < text.length) {
random.nextBytes(buf);

for (byte b : buf) {
if ((b >= 'a' && b <= 'z' || (b >= 'A' && b <= 'Z')) && b != 'O' && b != 'o' && b != 'l' && b != 'L' && b != 'i' && b != 'I') {
text[c++] = (char) b;
if (c >= text.length) {
break;
}
}
}
}

String f_string = new String(text).toLowerCase();
String S_string = f_string.substring(1, 5);
String t_string = f_string.substring(7, 9);
int ran = random.nextInt(100);
String final_string = random.nextInt(ran) + S_string + random.nextInt(ran) + t_string;
System.out.println("Random activation key: " + final_string.toLowerCase());
return final_string.toLowerCase();


}
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 04:22AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month