Your Turn
For each of the practice items, create the necessary variables and assign them to random values in the given range using the Random class.
Practice 1: Randomized Clinical Trials
To eliminate bias, assign a participant to whether they are in a treatment group or control group. A value of true
means treatment group and a value of false
means control group.
- Identify the variables that you will need as well as their types.
- Create necessary variables.
- Generate the random values needed using the Random class.
Practice 2: Simulate Weather Conditions
Model the initial weather conditions by providing values for temperature, wind speed, and rainfall.
- The value of temperature should be from -50C to 50C.
- The value of wind speed should be from 0 to 200 km/hr.
- The value of rainfall should be from 0 to 500mm.
- Identify the variables that you will need as well as their types.
- Create necessary variables.
- Generate the random values needed using the Random class.
Practice 3: Video Game Content Generation
Establish the initial item placement and item rarity for a game.
- The item placement is at a location from (0, 0) to (1000, 1000).
- The item rarity is from 1 to 10.
- Identify the variables that you will need as well as their types.
- Create necessary variables.
- Generate the random values needed using the Random class.
Practice 4: Randomizing Question Selection
Randomly select a quiz question from a bank of 5 questions.
- Identify the variables that you will need as well as their types.
- Create necessary variables.
- Generate the random values needed using the Random class.
Practice 5: Randomly Select a Customer for a Survey
A customer has a 1 in 3 chance of being selected to complete a survey.
- Identify the variables that you will need as well as their types.
- Create necessary variables.
- Generate the random values needed using the Random class.