Page 1 of 2 12 LastLast
Results 1 to 15 of 17

Math Help - R Language Random Number Generator

  1. #1
    Newbie
    Joined
    Feb 2011
    Posts
    6

    Exclamation 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.
    Last edited by amyt04; February 3rd 2011 at 04:31 PM.
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Master Of Puppets
    pickslides's Avatar
    Joined
    Sep 2008
    From
    Melbourne
    Posts
    5,236
    Thanks
    28
    I'm confused, how can it be random if it returns the same numbers each time.

    Can you give us more detail?
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Feb 2011
    Posts
    6
    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."
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Master Of Puppets
    pickslides's Avatar
    Joined
    Sep 2008
    From
    Melbourne
    Posts
    5,236
    Thanks
    28
    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?
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Newbie
    Joined
    Feb 2011
    Posts
    6
    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.
    Follow Math Help Forum on Facebook and Google+

  6. #6
    Master Of Puppets
    pickslides's Avatar
    Joined
    Sep 2008
    From
    Melbourne
    Posts
    5,236
    Thanks
    28
    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.
    Follow Math Help Forum on Facebook and Google+

  7. #7
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by amyt04 View Post
    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
    Follow Math Help Forum on Facebook and Google+

  8. #8
    Senior Member
    Joined
    Oct 2009
    Posts
    340
    Quote Originally Posted by CaptainBlack View Post
    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)
    Follow Math Help Forum on Facebook and Google+

  9. #9
    Newbie
    Joined
    Feb 2011
    Posts
    6
    Quote Originally Posted by theodds View Post
    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.
    Follow Math Help Forum on Facebook and Google+

  10. #10
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by amyt04 View Post
    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
    Follow Math Help Forum on Facebook and Google+

  11. #11
    Senior Member
    Joined
    Oct 2009
    Posts
    340
    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?
    Follow Math Help Forum on Facebook and Google+

  12. #12
    Super Member
    Joined
    Mar 2008
    Posts
    934
    Thanks
    33
    Awards
    1
    Quote Originally Posted by amyt04 View Post
    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.
    Follow Math Help Forum on Facebook and Google+

  13. #13
    Newbie
    Joined
    Feb 2011
    Posts
    6
    Quote Originally Posted by awkward View Post
    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.
    Follow Math Help Forum on Facebook and Google+

  14. #14
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    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.
    How about you post the actual wording of the assignment.

    CB
    Follow Math Help Forum on Facebook and Google+

  15. #15
    Newbie
    Joined
    Feb 2011
    Posts
    6
    Quote Originally Posted by CaptainBlack View Post
    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
    Follow Math Help Forum on Facebook and Google+

Page 1 of 2 12 LastLast

Similar Math Help Forum Discussions

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

Search Tags


/mathhelpforum @mathhelpforum