Question

PART B Write the following three methods: public int GetRandemniform(int min, int max) This method returns a random number fr
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Sol:

Functions are in c#

public int GetRandomUniform(int min, int max)

{

Random Rand = new Random();

return Rand.Next(min, max + 1);

}

public double GetRandomNormal(double mean, double

stddev)

{

Random Rand = new Random();

double r, phi, z, x;

// Box-Muller Transformation

r = Rand.NextDouble();

phi = Rand.NextDouble();

z = (Math.Cos(2 Math.PI r)) *

(Math.Sqrt(-2 * Math.Log(phi)));

// z is normal with mean = 0 and stddev = 1.

// We use our values of mean and stddev to

// scale z, giving us x.

x = z * stddev + mean;

return (x);

}

public int GetBinIndex(double mini, double maxi, int

NumBins, double ValueToBin)

{

Random Rand = new Random();

int BinIndex;

BinIndex = (int)Math.Ceiling((ValueToBin - mini) *

(NumBins / (maxi - mini)));

//ValueToBin is Pt to be assigned to a bin

//mini is Ptmin

//maxi is Ptmax

//NumBins is number of bins

return (BinIndex);

}

Add a comment
Know the answer?
Add Answer to:
PART B Write the following three methods: public int GetRandemniform(int min, int max) This method returns...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a public static method named getMaxOf2Ints that takes in 2 int arguments and returns the...

    Write a public static method named getMaxOf2Ints that takes in 2 int arguments and returns the Maximum of the 2 values Write a public static method named getMinOf2Ints that takes in 2 int arguments and returns the Minimum of the 2 values Write apublic static method named getMaxOf3Ints that takes in 3 int arguments and returns the Maximum of the 3 values Write a public static method named getMedianOf3Ints that takes in 3 int arguments and returns the Median Value...

  • I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that a...

    I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that accepts one integer parameter and returns the value raised to the third power as an integer. o Write a method called randominRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive. 2. o Write a method...

  • Project Objectives: To develop ability to write void and value returning methods and to call them...

    Project Objectives: To develop ability to write void and value returning methods and to call them -- Introduction: Methods are commonly used to break a problem down into small manageable pieces. A large task can be broken down into smaller tasks (methods) that contain the details of how to complete that small task. The larger problem is then solved by implementing the smaller tasks (calling the methods) in the correct order. This also allows for efficiencies, since the method can...

  • Using the following create the nessecary static methods to pass random arrays with the TempartureWithArrays and...

    Using the following create the nessecary static methods to pass random arrays with the TempartureWithArrays and Temperature classes -------------------------------------------------------------------------------------- public class TemperatureWithArrays {    public static final int ARRAY_SIZE = 5;    public static void main(String[] args)    {        int x;        Temperature temp1 = new Temperature(120.0, 'C');        Temperature temp2 = new Temperature(100, 'C');        Temperature temp3 = new Temperature(50.0, 'C');        Temperature temp4 = new Temperature(232.0, 'K');        Temperature tempAve =...

  • could you please help me with this problem, also I need a little text so I...

    could you please help me with this problem, also I need a little text so I can understand how you solved the problem? import java.io.File; import java.util.Scanner; /** * This program lists the files in a directory specified by * the user. The user is asked to type in a directory name. * If the name entered by the user is not a directory, a * message is printed and the program ends. */ public class DirectoryList { public static...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT