Results 1 to 3 of 3

Thread: Problem generating random numbers

  1. #1
    Okaf8547 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    203
    Rep Power
    4

    Default Problem generating random numbers

    I have a little problem with my generation of random numbers (that follow a standard normal distribution).

    In fact I created my little prog which fills me with an array of 10 float by float chosen according to Gauss' law:

    Code:
    # # include <iostream>
    # #include <cmath> # include <cmath>
    # #include <cstdio> # include <cstdio>
    # #include <cstdlib> # include <cstdlib>
    # #include <ctime> # include <ctime>
    # #include "gauss.h" # include "gauss.h"
    #
    # using namespace std; using namespace std;
    #
    #
    # double frand( double a, double b){ FRAND double (double a, double b) (
    #
    # return ( rand()/( double )RAND_MAX ) * (ba) + a; return (rand () / (double) RAND_MAX) * (ba) + a;
    # } )
    #
    # void RandomGauss( float * y) RandomGauss void (float * y)
    # { (
    # srand(( unsigned int ) time(NULL)); srand ((unsigned int) time (NULL));
    # // methode de Box-Muller / / Box-Muller
    # for ( int i=0;i<10;i++){ for (int i = 0; i <10; i + +) (
    # y[i] = sqrt(-2*log(frand(0,1)))*cos(2.*3.14*frand(0,1)); y [i] = sqrt (-2 * log (FRAND (0.1))) * cos (2 .* 3.14 * FRAND (0.1));
    #
    # } )
    # } )
    And I want to use a hand, the problem is that when I use multiple times "RandomGauss ()" in my hands, it simulates every time the same random distribution ...

    For those who will say what needs to srand blabla, it works does not it already appears in my and my gauss.cpp main.cpp

    Thank you in advance

  2. #2
    MACONAQUEA77 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    208
    Rep Power
    4

    Default

    srand should be done once primarily.

  3. #3
    Okaf8547 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    203
    Rep Power
    4

    Default

    I thought I had tested the srand unique in the hand, but apparently not, since now it works

    Thanx !

Similar Threads

  1. Random Hang up Problem
    By DavisNelson in forum Hardware Jargons
    Replies: 0
    Last Post: 03-15-2010, 11:14 AM
  2. Problem generating random numbers
    By mike iglesias in forum Programming
    Replies: 2
    Last Post: 02-19-2010, 11:23 AM
  3. C# program to print random numbers
    By Garcíarobine in forum Programming
    Replies: 2
    Last Post: 01-13-2010, 05:47 PM
  4. Generating a TOC
    By chreshel in forum Everything Else
    Replies: 0
    Last Post: 02-24-2009, 05:45 AM
  5. Generating a real key
    By Newtech32 in forum General Internet Terms
    Replies: 0
    Last Post: 03-29-2008, 10:25 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
SEO by SubmitEdge

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48