Random test generation in java

Posted on 2008-11-12
Medium Priority
Last Modified: 2012-05-05
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.
Question by:FranklinRaj22
LVL 86

Expert Comment

ID: 22937847
Try the following:
String randText = Integer.toString((int)(Math.random() * Integer.MAX_VALUE), 36);

Open in new window


Accepted Solution

aherps earned 1000 total points
ID: 22937872
Here is a web page which describes a decent function also:

LVL 15

Assisted Solution

quincydude earned 1000 total points
ID: 22937978
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;

Open in new window


Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month15 days, 8 hours left to enroll

850 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