# Thread: R Language Random Number Generator

1. ## R Language Random Number Generator

I need to find a random number generator algorithm that will produce the SAME 100000 numbers each time from 0 to 1 on a uniform distribution, and it cannot be runif. I cannot download a package.

I'm new to this, and I've tried everything, sample(), rnorm(), random package. The list goes on and on. I've been working on this for about 20 hours over the past three days with no luck. All of them produce DIFFERENT random numbers, but I can't seem to find anything that produces the same ones.

My professor hasn't replied to my requests for help, so I'm using this as a last resort.
This is part of a large semester project for my statistics class.

2. I'm confused, how can it be random if it returns the same numbers each time.

Can you give us more detail?

3. I'm sort of confused as well but here is what the professor told us:

"Your question: Must our RNG have an even or close to even distribution? Does it need to guarantee randomness to a certain precision? Must it be inclusive of 0 and 1?

Answer:I do not want randomness with extreme precision or with period one billion. I want that your team knows how to generate the random in [0,1]. Hence, you can use a simple random number generator. For example, I easily found one one the web and I wrote in R without using any seed function; I knows if I repeat many times I get always the same numbers but here we want just show the basic idea."

4. In ms-excel you can use rand(), which returns random numbers between 0 and 1 for as big a sample as you desire.

After you have these make a histogram, what do you get?

5. I can't use excel, it has to be done in R. I haven't found the correct algorithm so I don't have a histogram yet.

6. Sorry my frined, I use Excel, Minitab, SAS, SPSS, Maple and MATLAB but I don't use R.

I can suggest that after you have found a RNG and made a histogram then it should follow a unifrom distribution rather than a normal distribution.

7. Originally Posted by amyt04
I need to find a random number generator algorithm that will produce the SAME 100000 numbers each time from 0 to 1 on a uniform distribution, and it cannot be runif. I cannot download a package.

I'm new to this, and I've tried everything, sample(), rnorm(), random package. The list goes on and on. I've been working on this for about 20 hours over the past three days with no luck. All of them produce DIFFERENT random numbers, but I can't seem to find anything that produces the same ones.

My professor hasn't replied to my requests for help, so I'm using this as a last resort.
This is part of a large semester project for my statistics class.
There will be a function somewhere to set the initial state for the random number generators internal sate vector. You need to find that function, it will allow you to extract the current/initial state, and then you reset the state to the saved value every time you want a repeatable set of numbers.

Method 2: set up an array of 100000 elements, fill it with random numbers and use these in your program.

CB

8. Originally Posted by CaptainBlack
There will be a function somewhere to set the initial state for the random number generators internal sate vector.
In R, this function is set.seed(), where the argument is your favorite number. So, to generate the same 10000 random uniforms, in R, do

> set.seed(51987)
> x <- ruinf(10000)

9. Originally Posted by theodds
In R, this function is set.seed(), where the argument is your favorite number. So, to generate the same 10000 random uniforms, in R, do

> set.seed(51987)
> x <- ruinf(10000)

we cannot use seeds what I am assuming is that my professor wants us to use some algorithm that will generate the same numbers. however I am not sure how to implement any algorithm in R.

10. Originally Posted by amyt04
we cannot use seeds what I am assuming is that my professor wants us to use some algorithm that will generate the same numbers. however I am not sure how to implement any algorithm in R.
That makes no sense, in an earlier post you were using the random number generators.

CB

11. I'm with CB on this one. What is the exact wording on the assignment? If you can't set the seeds in R, can you copy an existing, well-known, random number generator and hard code the seed in?

12. Originally Posted by amyt04
I'm sort of confused as well but here is what the professor told us:

"Your question: Must our RNG have an even or close to even distribution? Does it need to guarantee randomness to a certain precision? Must it be inclusive of 0 and 1?

Answer:I do not want randomness with extreme precision or with period one billion. I want that your team knows how to generate the random in [0,1]. Hence, you can use a simple random number generator. For example, I easily found one one the web and I wrote in R without using any seed function; I knows if I repeat many times I get always the same numbers but here we want just show the basic idea."
I think your prof is asking you to write your own random number generator function in R, using some simple well-known algorithm such as the Park-Miller algorithm:

Lehmer random number generator - Wikipedia, the free encyclopedia

If you know how to write R code it shouldn't be difficult.

13. Originally Posted by awkward
I think your prof is asking you to write your own random number generator function in R, using some simple well-known algorithm such as the Park-Miller algorithm:

Lehmer random number generator - Wikipedia, the free encyclopedia

If you know how to write R code it shouldn't be difficult.

YES! This is what I needed. I do have a problem with this though. I made an empty vector that holds the 10000 values i need, and then used the for loop to move along the vector. A lot of these algorithms got to values of 40000000, or 2000000. Should I just divide the vector by 40000000 or 2000000 respectively to make sure its on [0,1], or is there a way to fix the constants so that it doesn't do that?

Thank you so much. I'm sorry for the confusion. This is the first time my professor has taught an undergrad class, and all his assignments are very ambiguous.

14. Originally Posted by amyt04
YES! This is what I needed. I do have a problem with this though. I made an empty vector that holds the 10000 values i need, and then used the for loop to move along the vector. A lot of these algorithms got to values of 40000000, or 2000000. Should I just divide the vector by 40000000 or 2000000 respectively to make sure its on [0,1], or is there a way to fix the constants so that it doesn't do that?

Thank you so much. I'm sorry for the confusion. This is the first time my professor has taught an undergrad class, and all his assignments are very ambiguous.
How about you post the actual wording of the assignment.

CB

15. Originally Posted by CaptainBlack
How about you post the actual wording of the assignment.

CB
Project #1 assignment 2
In lesson #3 we used the R function runif(1) to generate random numbers.
Hence, find a simple random number generator in [0,1].
Write a small script using R
Generate 10000 random numbers.
Plot the random numbers

Later on he said this:
You should not use R functions or libraries; you should look on the web for an algorithm about random number generators.

I used x(n+1)=a*x(n)*mod m

Page 1 of 2 12 Last

### r language ran

Click on a term to search for related topics.