a very large interval of rundom numbers

This is a discussion on a very large interval of rundom numbers within the C++ Programming forums, part of the General Programming Boards category; It's an integer (unless .RandInt means something different). Cast it or something, I guess. EDIT: Couldn't you do something like ...

  1. #16
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    It's an integer (unless .RandInt means something different). Cast it or something, I guess.





    EDIT: Couldn't you do something like this (un-debugged):

    Code:
    int Rand( unsigned int UpperValue )
    {
    	unsigned int Bound = 0;
    
    	while ( Bound < UpperValue )
    	{
    		Bound *= rand();
    	}
    
    	return Bound%UpperValue;
    }
    then divide that by the 14 million number?

    unless I'm completely missing the point again
    Last edited by twomers; 08-02-2006 at 01:38 PM.

  2. #17
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    In that case I guess you do need something more complicated than a simple call to rand() and perhaps the MTRand, boost's random library, or some other more advanced random number generator can help you out.

  3. #18
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,412
    RandInt() will produce unsigned longs in the range specified by the machine where it is run. Usually, for 32 bit machines this means 2^32, which is more than enough for your needs.

    Just as Daved suggested, The Boost library is another option.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  4. #19
    Registered User
    Join Date
    Aug 2006
    Posts
    10
    Thank you very much for all of replys, you have helped me very much. I think that now I generate very well my random numbers with the algorithm that I have pasted before and therefore I will continue my project of end of career, this is one example of the numbers:

    0.165794,0.0661423,0.923107,0.531084,0.34571,0.203 416,0.029796,0.230248,0.232488,0.3
    13662,0.290937,0.399191,0.268811,0.0109423,0.72024 4,0.971198,0.747598,0.391661,0.841
    39,0.503972,0.516979,0.889657,0.662066,0.386967,0. 165785,0.818416,0.44327,0.397976,0.
    912517,0.141096,0.225495,0.417585,0.681512,0.35767 8,0.728592,0.849111,0.944788,0.713
    195,0.768732,0.169899,0.330627,0.935429,0.0824016, 0.596916,0.708728,0.800829,0.50701
    4,0.562885,0.424306,0.492069,0.0279898,0.905467,0. 898149,0.470343,0.368699,0.582445,0.290043,0.57629 ,0.47501,0.898634,0.645065,0.504504,0.45487,0.8500 83,0.733836,0.215999,
    0.635212,0.869203,0.687654,0.901373,0.149824,0.814 778,0.396815,0.555215,0.4301,0.8225
    78,0.0158782,0.53381,0.283836,0.670007,0.273425,0. 834816,0.969183,0.94561,0.607918,0.
    319848,0.333663,0.350953,0.572609,0.393557,0.73656 9,0.548893,0.471629,0.249477,0.978
    695,0.905908,0.197679,0.795876,0.216934,0.0718069, 0.155776,0.0472373,0.442245,0.
    Thanks.

  5. #20
    Registered User
    Join Date
    May 2002
    Posts
    66
    http://www.mathcom.com/corpdir/techi...ifaq/q210.html

    Look for L'Ecuyer or Marsaglia, both have written large period random numbers and C algorithms are available online.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Handling Large Numbers
    By Xzyx987X in forum C Programming
    Replies: 2
    Last Post: 05-03-2004, 02:33 PM
  2. Using really big numbers!
    By Machewy in forum C++ Programming
    Replies: 11
    Last Post: 02-26-2004, 09:49 AM
  3. Help needed with VERY large numbers.
    By jwarner in forum C++ Programming
    Replies: 4
    Last Post: 01-18-2004, 11:01 AM
  4. large numbers
    By Alextheking in forum C++ Programming
    Replies: 13
    Last Post: 01-09-2004, 02:51 PM
  5. the definition of a mathematical "average" or "mean"
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 12-03-2002, 10:15 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21