Page 2 of 2 FirstFirst 12
Results 16 to 17 of 17

Thread: R Language Random Number Generator

  1. #16
    Grand Panjandrum
    Nov 2005
    Quote Originally Posted by amyt04 View Post
    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.

    Follow Math Help Forum on Facebook and Google+

  2. #17
    Super Member
    Mar 2008
    Quote Originally Posted by amyt04 View Post
    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.

    [edit] Oops, I see Captain Black has already told you this.[/edit]
    Follow Math Help Forum on Facebook and Google+

Page 2 of 2 FirstFirst 12

Similar Math Help Forum Discussions

  1. Replies: 2
    Last Post: Jul 29th 2010, 05:48 AM
  2. Random Sequence Generator
    Posted in the Math Forum
    Replies: 0
    Last Post: Jul 3rd 2010, 08:38 AM
  3. Minimum number of generator assemblies
    Posted in the Advanced Algebra Forum
    Replies: 2
    Last Post: Sep 9th 2009, 12:41 AM
  4. Random Number Generator
    Posted in the Math Challenge Problems Forum
    Replies: 3
    Last Post: Oct 22nd 2008, 12:22 AM

Search tags for this page

Click on a term to search for related topics.

Search Tags

/mathhelpforum @mathhelpforum