• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 909
  • Last Modified:

Random test generation in java

I need to create and send a random text to a user whenever a new user id is created ... i don wanna involve any cipher to create this random text... this should be purely random  , can you help me in writting a random text generator code in java.
0
FranklinRaj22
Asked:
FranklinRaj22
2 Solutions
 
CEHJCommented:
Try the following:
String randText = Integer.toString((int)(Math.random() * Integer.MAX_VALUE), 36);

Open in new window

0
 
aherpsCommented:
Here is a web page which describes a decent function also:

http://www.daniweb.com/code/snippet851.html
0
 
quincydudeCommented:
This one will make a random string of upper case letters of your choice



	public static void main(String[] args) {
		// TODO Auto-generated method stub
		 int achar;
		 char i;
		 String randomKey = "";
		 
		 for(int y = 0; y < 10; y++)
		 {
		 achar = 65 + (int)((Math.random() * Integer.MAX_VALUE)%26);
		 i = (char)achar;
		 randomKey = randomKey + i;
		 }
		 System.out.println(randomKey);
	}

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now