0% found this document useful (0 votes)
8 views2 pages

Programs On Random Class

The document outlines ten Java programming tasks that utilize the Random class. These tasks include generating random passwords, integers, lottery numbers, and colors, as well as simulating dice rolls, coin tosses, and random walks. Each task is designed to demonstrate different functionalities of randomness in programming.

Uploaded by

thulasirgukt307
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Programs On Random Class

The document outlines ten Java programming tasks that utilize the Random class. These tasks include generating random passwords, integers, lottery numbers, and colors, as well as simulating dice rolls, coin tosses, and random walks. Each task is designed to demonstrate different functionalities of randomness in programming.

Uploaded by

thulasirgukt307
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Programs on Random class

1. Generate a Random Password

Write a Java program that generates a random password. The password should be a mix of upper
and lowercase letters, digits, and special characters. The length of the password should be
specified by the user.

2. Random Integer within a Range

Create a Java program that generates a random integer between a given range, for example,
between min and max, where min and max are user inputs. Print the result.

3. Simulate a Dice Roll

Using the Random class, simulate the rolling of a 6-sided die. The program should generate a
random number between 1 and 6 each time it is run and print the result.

4. Lottery Number Generator

Write a Java program that generates 6 unique random lottery numbers in the range 1 to 49.
Ensure that there are no duplicate numbers.

5. Randomly Shuffle an Array

Write a Java program that takes an array of strings (for example, a deck of cards) and shuffles
the elements randomly using the Random class. After shuffling, print the array.

6. Simulate Coin Toss

Write a program that simulates a coin toss (Heads or Tails) using the Random class. Print "Heads"
or "Tails" based on the random result.

7. Randomly Select a Question from a Question Bank

Given a list of questions (e.g., in an array or list), write a Java program that selects a random
question each time it is run. This can be useful for creating quizzes or tests.

8. Random Floating-Point Number Generator

Write a Java program that generates a random floating-point number between a given range (e.g.,
between 0.0 and 1.0). Then, print the generated number.
9. Random Color Generator

Create a Java program that generates a random color by randomly selecting values for the red,
green, and blue components, each in the range [0, 255]. Display the color in a GUI or in the
console as RGB values.

10. Simulate a Random Walk

Write a Java program to simulate a random walk of a particle in 1D (moving left or right). The
program should generate random steps (e.g., -1 or +1) and keep track of the particle's position
over a series of steps.

You might also like