Question

In: Computer Science

c++ give ways of filling array of uniform random numbers

c++

give ways of filling array of uniform random numbers

Solutions

Expert Solution

1) Array of random numbers using C++ program,

Create an array:

int my_array[100];. Seed the random number generator srand(0​);.

Loop over your array and fill it up!:

int i;

for (i = 0; i < 100; i++)

try to get a 20 element array to fill with random numbers from rand. I was told using % 99 is 100 since the count starts at 0. Test and using brackets and +1 with my array increments the array to the next value and doesn't add 1.

2) Fill array with random numbers, Simple programming task - fill array with random integer values. We need to include time. h to Duration: C++ library has a function that generates random numbers, called the rand() function.

code:

#include<iostream>
#include<stdlib.h>
#include<time.h>
using namespace std;
int main()
{
srand(time(NULL));
const unsigned int sizeOfArray =10;
int numberArray[sizeOfArray];

for(int i=0;i<sizeOfArray;i++)
{
numberArray[i]=rand()%50;
cout<<numberArray[i]<<endl;
}
numberArray[0]=500;
numberArray[9]=1000;

for(int i=0; i<sizeOfArray ; i++)
{
cout<<numberArray[i]<<endl;
}

system("PAUSE");
return 0;
}

output:

13
42
5
22
46
36
22
10
46
35
500
42
5
22
46
36
22
10
46
1000

code(SS):

output(SS):

This is ways of filling array of uniform random numbers.


Related Solutions

Write a function that will generate an array of random numbers. It needs to:
DO IN C++Write a function that will generate an array of random numbers. It needs to:Take 3 integers as parameters-The first is the minimum value-the second is the maximum value-the third is the size of the new array-create a dynamically allocated array of the correct size-generate a random number (between min and max) for each element in the array-return a pointer to the arrayCreate a main() function that tests the above function and displays the values in the random array.
I'd like to have 30 random numbers generated which are distributed a) exponentially b) uniform c)...
I'd like to have 30 random numbers generated which are distributed a) exponentially b) uniform c) normal d) binomial e) Poisson Would you please generate 30 random numbers regarding these distributions above, please? Mean=3 Variance is 2
(code in C++ language) [Code Bubble sort, Insertion sort Create a Big array with random numbers....
(code in C++ language) [Code Bubble sort, Insertion sort Create a Big array with random numbers. Record the time. Run Bubble Check time (compute the processing time) do it 100 times (random numbers) Take the average Insertion: Compare] (some explanations please)
1.) Generate an array of 10 random numbers between 1 - 100 2.) Copy the array...
1.) Generate an array of 10 random numbers between 1 - 100 2.) Copy the array to a temp array 3.) Call each of the methods to sort (bubble, selection, insertion, quick, merge), passing it the array 4.) In-between the calls, you are going to refresh the array to the original numbers. 5.) Inside of each sorting method, you are going to obtain the nanoseconds time, before and after the method Subtract the before time from the after time to...
Suppose you have access to a random number generator Rng() that generates uniform random numbers in...
Suppose you have access to a random number generator Rng() that generates uniform random numbers in {0, 1, . . . , n − 1}. Design a function uses Rng() generate a uniform random number in {0, 1, . . . , m − 1}, where m ≤ n
Write a program that asks the user to enter an array of random numbers, then sort...
Write a program that asks the user to enter an array of random numbers, then sort the numbers (ascending order), then print the new array, after that asks the user for a new two numbers and add them to the same array and keep the array organization. (c++ ) (using while and do while loops)
In C an array Numbers is declared float Numbers[10][10]. Due to a bug, the program tried...
In C an array Numbers is declared float Numbers[10][10]. Due to a bug, the program tried to reference Numbers[11][-13]. Which element of Numbers will actually be accessed?
How to inhabit the int array num with random numbers using a function that you then...
How to inhabit the int array num with random numbers using a function that you then invoke from the main method. I already created a function that generates an array of 5 random integers. /* int i;   int arrayName[5];     for(i= 0;i < 6; i++ ){            //type arrayName[arraysize];            arrayName[i] = rand()% 200;       printf("array[%d] = %d\n",i,arrayName[i]); */ // use rand() % some_number to generate a random number int num[5]; int main(int argc, char **argv) { // hint // function invocation goes here...
Write the R code to generate five independent uniform random numbers and use that to generate...
Write the R code to generate five independent uniform random numbers and use that to generate 5 independent Bernoulli random variables with probability of success p = 0.4. please use RStudio. please do not use lab nor rbern for calculations.
Write a Java program that creates an array with 20 random numbers between 1 and 100,...
Write a Java program that creates an array with 20 random numbers between 1 and 100, and passes the array to functions in order to print the array, print the array in reverse order, find the maximum element of the array, and find the minimum element of the array. The prototype of the methods: public static void printArray(int arr[]) public static void printArrayReverse(int arr[]) public static int searchMax(int arr[]) public static int searchMin(int arr[]) Sample output: Random Array: [17 67...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT