Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Generating Independent Random Sequences in C

Options
  • 08-06-2010 11:13am
    #1
    Registered Users Posts: 9,579 ✭✭✭


    Hi There,

    I'm making a simulation program that adds Gaussian Noise to X,Y coordinates. Both X and Y will be drawing samples from different normal distributions.

    I'm using the Box Muller method to do this from the uniform distribution provided by the rand() function in C.

    The problem I'm having is, that every time I call the box muller method, it works off the same random sequence that was originally seeded and I don't think things are coming out Gaussian distributed :-/

    In C#, you can create a Random object with its own seed but unfort in C you can only seed it once and every call will work off the same sequence. For this reason.

    I hope ye understand what I'm saying here.


    Any ideas? :)


Comments

  • Registered Users Posts: 18 emmerdale


    Maybe I don't fully understand what you are asking, but are you using the srand () function to seed the RNG before calling rand ()?


  • Registered Users Posts: 9,579 ✭✭✭Webmonkey


    emmerdale wrote: »
    Maybe I don't fully understand what you are asking, but are you using the srand () function to seed the RNG before calling rand ()?
    Yeah I know about srand thanks. That's not the problem though. I want multiple sequence of uniform samples from 0 - 1. However, if I've multiple things using the same rand method, some part of the distribution get used for one box muller and other for another. I cannot re seed each time either I don't think as it won't be uniform distribution? - least I'm thinking that.


Advertisement