Adding another child process, to run in the background, to your current project
ID: 3705772 • Letter: A
Question
Adding another child process, to run in the background, to your current project The Poincaré Recurrence Theorem Given two urns, one empty (call it urn 2) and one full with numbered mar bles, numbered from 1 to n (cal u). Take pieces of paper with numbers piece of paper from the hat and move the corresponding numbered marble from one urn to the other Keep doing this process and end when all the marbles are returned back in urn 1 from 1 to n and put them in a hat. Choose a random Normally, or intuitively, you would think that this process would create a somewhat steady state of equa number of marbles in urn 1 and urn 2. This may be true for some time. However and according to the Poincaré recurrence theorem, there will be a time (a finite time) when the system returns to its original state with all the numbered marbles back in urn 1. This may take some pen, so as a suggestion let n 20 or 30 and then try it for t your program run all night then perhaps try n 70 or time for this to hap n 50. If you would le 80 You should record the number of times you called a number from the hat (as the time and/or you may choose to use the Linux clock) function. Of course this should be a child process running in the background sincet will usually take a long time. You may also want to use the unsigned long long integer data type to count the number of times you execute the process by calling a number from the hat Requirements: 1. A complete program listing 2. A complete program description (how did you program the project, input and output requirements, etc.) 3. Test runs and reasons for your test run choices . A time analysis, either with counting the number of number calls from the hat or using the Linux clock function. Conclusions from this analysisExplanation / Answer
1.program:
#include<stdio.h>
#include<stdlib.h>
int main()
{
unsigned long long int count=0;
int n,i,hat;
puts("enter value you want to check ");
scanf("%d",&n);
while(n<=0)
{
printf("please enter positive number: thanks ");
scanf("%d",&n);
}
int *urn2=(int*)malloc(n);
int *urn1=(int*)malloc(n);
for(i=0;i<n;i++)
urn1[i]=i+1;
int urn2size=0,urn1size=n;
do
{ count++;
hat=(rand()%n)+1;
if(urn1[hat-1]!=0)
{
urn2[hat-1]=hat;
urn1[hat-1]=0;
urn2size++;
urn1size--;
}
else
{
urn1[hat-1]=hat;
urn2[hat-1]=0;
urn2size--;
urn1size++;
}
}while(urn1size!=n);
printf("no of pickings from hat is = %llu",count);
}
2.description:
/* 1.urn1 and urn2 are allocated dynamically using malloc function;
2.hat is taken as a simple integer and we can randomly pick value to hat by using c rand()function,and make the value of hat
between 1 to n by using %(modulus)n trick;
3.output count is unsigned long long integer
*/
3.TEST RUN:
n= -100
n=0
number can't be negative and zero:
4.calls from the hat:
n=10 count=2804
at some point it is obvious that all the marbles comes to urn1 again
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.