Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

2. If an equal likelihood of each of several discrete events exists, in a simulation we can generate a random integer to indicate the choice.

2. If an equal likelihood of each of several discrete events exists, in a simulation we can generate a random integer to indicate the choice. For example, in a simulation of a pollen grain moving in a fluid, suppose at the next time step the grain is just as likely to move in any directionnorth, east, south, west, up, or downin a three-dimensional (3D) grid. A probability of 1/6 exists for the grain to move in any of the six directions. With these equal probabilities, we can generate a uniformly distributed integer between 1 and 6 to indicate the direction of movement.

Suppose in a simulation involving animal behavior, a lab rat presses a food lever (FOOD = 1) 15% of the time, presses a water lever (WATER = 2) 20% of the time, and does neither (NEI- THER = 3) the remainder of the time. For the simulation, we consider the range split into three parts, and again generate a uniformly distributed ran- dom floating-point number from 0.0 to 1.0. If the number is less than 0.15, which occurs 15% of the time, we assign FOOD = 1 to the rats action. For 20% of the time, the uniformly distributed random number is greater than or equal to 0.15 and less than 0.35. With a random number in this range, we make the rats action be WATER = 2. A random number is greater than or equal to 0.35 with a probability of 65%. In such a case, we assign NEITHER = 3 to the rats action. Thus, with rand being a uniformly distributed random floating-point number from 0.0 to 1.0, we em- ploy the following logic for determination of the rats action:

if a random number, rand, is < 0.15

the rat presses the food lever

else if rand < 0.35 (i.e., 0.15 ? rand < 0.35)

the rat presses the water lever

else (i.e., 0.35 ? rand)

the rat does neither

Using the above logic used in determining the action of a rat, write a segment to return FOOD, WATER, or NEITHER, depending on the value of the random number. ?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions