Solution:
To generate the random number between (0,15) in python
import random #Import the random library to generate the random numbers
#Random Generator Function to get the random numbers between the range
def randomNumber_Generator():
#declare array to store the random numbers
randomNumber=[]
#using for loop generate 500 random numbers between 1to 15
for i in range(1,500):
val=random.randrange(0,15); #Using randrange module of random generate number
randomNumber.append(val) #append value to the list
return randomNumber; #return list of 500 random numbers
Calculate Mean:
Formula to calucale the Mean is S
for eg let us take list number {1,2,3,4,5} & list size is 5
1+2+3+4+5/5=15/5
15/5=3
mean=5
In our case the Mean formula will be Sum of the each element in random Array/500
Program:
#Method to Calculate MEan value
def CalculateMean(value):
# Initialize sum as Zero
sum=0;
#Using for loop iterate random array and find sum of all values
for j in range(0,len(value)):
sum=sum+value[j];
#Divide the sum by the length of array
result=sum/len(value);
#return result
return result;
Standart Deviation:
Formula To Calculate StandardDeviation =
step 1: Calculate Mean value for the list .Let us Consider above example 1+2+3+4+5=15/5=3
step2: Calculate square of Differente between elements and mean
step 3: Calculate sum of the square calculated in above steps
4+1+0+1+4=10
step 4 Calculate sumof the square divided by n-1
10/4=2.5
step5: Take Square root of the value
=
1.58
Similar Steps are followed in the program for the 500 random number
#method to calculatestandarddeviate
def CalculateStandardDeviation(randomNum,m):
sum=0;
# loop to calculate sum of (number-mean)^2
for k in range(0,len(randomNum)):
sum=sum+(randomNum[k]-m)*(randomNum[k]-m);
#Divide sum of square by len of array -1 (here it is499)
result=sum/(len(randomNum)-1);
#return take square root of result and return it
return math.sqrt(result);
Whole Program:
import math #Import to call sqrt of maths function
import random #Import the random library to generate the random numbers
#Main Method
def main():
#call the randomNumber_Generator method
randomNumbers=randomNumber_Generator();
#Call CalculateMeanMethod to get Mean
mean=CalculateMean(randomNumbers)
print("Mean Value:",mean);
#Call CalculateStandardDeviation to standardDeviation
standardDeviation=CalculateStandardDeviation(randomNumbers,mean);
print("Standard Deviation:",standardDeviation);
#Random Generator Function to get the random numbers between the range
def randomNumber_Generator():
#declare array to store the random numbers
randomNumber=[]
#using for loop generate 500 random numbers between 1to 15
for i in range(1,500):
val=random.randrange(0,15); #Using randrange module of random generate number
randomNumber.append(val) #append value to the list
return randomNumber; #return list of 500 random numbers
#Method to Calculate MEan value
def CalculateMean(value):
# Initialize sum as Zero
sum=0;
#Using for loop iterate random array and find sum of all values
for j in range(0,len(value)):
sum=sum+value[j];
#Divide the sum by the length of array
result=sum/len(value);
#return result
return result;
#Method to calculate standardDeviation
def CalculateStandardDeviation(randomNum,m):
sum=0;
#Loop to claculate sum of the random number -mean square
for k in range(0,len(randomNum)):
sum=sum+(randomNum[k]-m)*(randomNum[k]-m);
#Divide sum by the length of array -1
result=sum/(len(randomNum)-1);
#return square root of the result
return math.sqrt(result);
#Used to call Main Method
if __name__ == "__main__":
main()
Ouput 1:
Mean Value: 6.8997995991983965
Standard Deviation: 4.414058860324523
Output 2:
Mean Value: 7.110220440881764
Standard Deviation: 4.318387387674145
Output 3:
Mean Value: 6.8937875751503
Standard Deviation: 4.372093582270911
Note:In the above program I didn't used the statistic library to calculate mean and standart deviation.If you want you can import statictics to calculate meann & SD.Kindly refer below code for that
import statistics #Import to call Mean and Standard deviation
import random #Import the random library to generate the random numbers
#Main Method
def main():
#call the randomNumber_Generator method
randomNumbers=randomNumber_Generator();
#Call CalculateMeanMethod to get Mean
mean=CalculateMean(randomNumbers)
print("Mean Value:",mean);
#Call CalculateStandardDeviation to standardDeviation
standardDeviation=CalculateStandardDeviation(randomNumbers,mean);
print("Standard Deviation:",standardDeviation);
#Random Generator Function to get the random numbers between the range
def randomNumber_Generator():
#declare array to store the random numbers
randomNumber=[]
#using for loop generate 500 random numbers between 1to 15
for i in range(1,500):
val=random.randrange(0,15); #Using randrange module of random generate number
randomNumber.append(val) #append value to the list
return randomNumber; #return list of 500 random numbers
#Method to Calculate MEan value
def CalculateMean(value):
#Calculate the value using statistics mean method
result=statistics.mean(value);
#return result
return result;
#Method to calculate standardDeviation
def CalculateStandardDeviation(randomNum,m):
#Calculate it by passing array & mean value
result=statistics.stdev(randomNum, xbar = m);
#return square root of the result
return result;
#Used to call Main Method
if __name__ == "__main__":
main()
Output:
Mean Value: 7.038076152304609
Standard Deviation: 4.387888715055942
Output:
Mean Value: 6.907815631262525
Standard Deviation: 4.224084587277824
Write a program that uses the rand function to generate 500 integers, in the range [0,15)....
Write a python program to generate a PDF of a normally distributed function with the range from 10 to 45 with a standard deviation of 2 This is what I have currently: mu=() # mean sigma=2 # standard deviation x=np.arange(10,45,0.1) y=stats.norm.pdf(x, x.mean(), sigma) plt.plot(x,y) plt.show() If I am incorrect, please explain what I am doing wrong and why (so I am able to understand for future problems). Thank you!
Write a C program that uses the random number generator rand( ) to create an array with 20 numbers with value in the range from 1 to 100. The program calculates and displays the difference between the largest array element and the second largest array element in the array.
Using simple python code import random Your program should: generate positive random integers in the range of 1 to 500 count the number of iterations. update and output the highest number generated.
Write a program in C that creates an array of 100 random numbers from 0-99. The program sums the random numbers and prints the sum. It then writes the numbers to a new file using open, close and write. Then looks in the current directory for files that match the pattern “numbers.XXXX”. For each file, open the file and read the file. You can assume that the file will contain 100 integers. Sum the integers. Print the filename and the sum...
c# prograaming language
1. write a program that generates 10,000 random integers in the
range of 0-9 and them in binary search tree.
2. use any sort algorithm (insertion, bubble, quick...) to
display a list of each of the integers and how many times they
appear.
3. at last, add ruction to the BinarySearchTree class that count
the number of edges in a tree.
Write a program that generates 10,000 random integers in the range of 0-9 and store them...
Write a program in C to generate random numbers. The program recieves 4 items on activation through argv: 1. Name of the data file 2. Number of items for program to generate 3. Range of numbers 4. Seed of the random number generator Example run: ./rand datafile.txt 20 1000 3127 Program must convert all numbers to ints using atoi(), must save all parameters into variables, opens the data file to write the random numbers into it, program loops to generate...
that can calculate several statistical measures of data. Write a program collects N integers from the user (N is a positive integer entered by the user). Then, the program prompts the user for an option: 1- to find the minimum, 2- to find the maximum, 3- to find the mean, 4-to find the standard deviation. In addition to the main method, your program must contain four methods with the following headers: The program public static int min(intlI A) public int...
Write a simple program that pushes 25 random integers (you select the range) into a vector. Write a function that receives the vector as a parameter. Make that function add up all of the odd numbers in the vector and return the sum.
(C++)Write a program that generates twenty five random integers between 0 and 24 and display the sum of even integers. (Hint: Use rand()%25 to generate a random integer between 0 and 24. Use an array of 25 integers, say num , to store the random integers generated between 0 and 24.)
Write and test a program to rotate values in an array of 10 integers to the left by 1. Use rand and srand to generate the array with random integers. Example: input; [34, 57, 89, 54, 11, 20, 21, 99, 23, 72] Output : [57, 89, 54, 11, 20, 21, 99, 23, 72, 34]