# Thread: R Language Random Number Generator

1. Originally Posted by amyt04
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
You use a number y=x/m as you random number in the range [0,1), which is what it will say in the references if you look.

CB

2. 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.
Divide by the maximum value to reduce the numbers to the range [0,1]. For a linear congruential RNG, the max value is the modulus, 2^31-1 in the case of the Park-Miller generator.

 Oops, I see Captain Black has already told you this.[/edit]

Page 2 of 2 First 12