Question

Random number generator 1: Search for algorithms generating pseudo-random numbers. Select one of them for generating...

  1. Random number generator 1:
    Search for algorithms generating pseudo-random numbers. Select one of them for generating a pseudo-random sequence. Original sample can be generated in any form: binary, decimal, etc. But submitted sample must be in the form of uniform random numbers on [0,1][0,1]. The sample should not be generated by any function, like runif(), sample(), etc. Instead it must be some algorithm that you code yourselves. For example, mid-square algorithm, Fibonacci-based algorithm, etc.
  2. Random number generator 2:
    Find some “natural” source of randomness, meaning not a pseudo-random generator algorithm. Generate a sample, if the sample is not in the form of uniform on [0,1][0,1] then transform it in thate uniform format.

Please use r as the programming language

Homework Answers

Answer #1

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
  
int main()
{
srand(time(NULL));
int i;
  
for(i = 0; i<5; i++)
printf("%d\t", rand()%10);
}

/* code to generate n random numbers with lower and upper limits*/
#include<stdio.h>
#include<time.h>
int l,u;
int* randomn(int A[],int n);
void main()
{
int i,n,A[20];
int *arr;
printf("Enter how many random no you want to print :\n");
scanf("%d",&n);
printf("Enter lower and upper limit of random nimbers: \n");
scanf("%d%d",&l,&u);
arr=randomn(A,n);
printf("%d Random numbers: \n",n);
for(i=1;i<=n;i++)
printf("%d ",A[i]);
printf("\n");
}
int* randomn(int A[20],int n)
{
int i;
srand(time(0));
for(i=1;i<=n;i++)
A[i]=(rand()%(u-l+1))+l;
return A;
}

Know the answer?
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
Similar Questions