# About Random perturbation

 User Name Remember Me Password
 Register Blogs Members List Search Today's Posts Mark Forums Read

 LinkBack Thread Tools Display Modes
 July 13, 2005, 10:58 I want to obtain a random valu #1 Member   zoujianfeng Join Date: Mar 2009 Location: Hangzhou, China Posts: 30 Rep Power: 8 I want to obtain a random value at each 'imode' loop: for(int imode=1;imode<=10;imode++) { Random pertA(1234567); ampA=pertA.GaussNormal(); Info<<"ampA:"<

 July 13, 2005, 11:05 Move Random pertA(1234567) #2 Senior Member   Join Date: Mar 2009 Posts: 854 Rep Power: 13 Move Random pertA(1234567); to before the loop.

 July 13, 2005, 22:52 Thank you, Henry. The result i #3 Member   zoujianfeng Join Date: Mar 2009 Location: Hangzhou, China Posts: 30 Rep Power: 8 Thank you, Henry. The result is nice. But some of the random values are big than 1 or less than -1. Why? I cannot find the implementation file Random.C of the class Random. In the sub-directory 'src/OpenFOAM/primitives/random/', I found a file called Random.C which is not the right one. I use OpenFOAM1.1.

 July 14, 2005, 04:34 Random.C is the right one, Gau #4 Senior Member   Join Date: Mar 2009 Posts: 854 Rep Power: 13 Random.C is the right one, GaussNormal() is the last function in that file: // return a normal Gaussian randon number // with zero mean and unity variance N(0, 1) scalar Random::GaussNormal() { static int iset = 0; static scalar gset; scalar fac, rsq, v1, v2; if (iset == 0) { do { v1 = 2.0*scalar01() - 1.0; v2 = 2.0*scalar01() - 1.0; rsq = v1*v1 + v2*v2; } while (rsq >= 1.0 || rsq == 0.0); fac = sqrt(-2.0 * log(rsq)/rsq); gset = v1*fac; iset = 1; return v2*fac; } else { iset = 0; return gset; } } I am not sure if this method is required to limit the values between -1 and 1. If it is an issue for you I suggest you clip the values although this will probably distort the Gaussian distribution slightly.

 July 14, 2005, 05:08 That file is random.c not Rand #5 Senior Member   Join Date: Mar 2009 Posts: 854 Rep Power: 13 That file is random.c not Random.C, do you have a case-insensitive filing system?

 July 14, 2005, 05:18 Sorry, I have found the right #6 Member   zoujianfeng Join Date: Mar 2009 Location: Hangzhou, China Posts: 30 Rep Power: 8 Sorry, I have found the right Random.C file in my cluster machines where I have installed the full package. Maybe when I transfer the source files from the cluster machines to my local PC, the file random.C overrided Random.C. Sorry for time wasting.

 May 18, 2006, 05:22 Dear Zou Mo Gauss distributio #7 Senior Member   Mieszko Młody Join Date: Mar 2009 Location: POLAND, USA Posts: 129 Rep Power: 8 Dear Zou Mo Gauss distribution with mean 0 and variance 1 , can give values less than -1 or higer than 1.

 December 4, 2007, 04:05 Hello everybody I want to o #8 Senior Member   Marhamat Zeinali Join Date: Mar 2009 Location: Tehran, Tehran, iran Posts: 107 Rep Power: 8 Hello everybody I want to obtain n random values for use at each runtime , by using OF Random-class. But prooduced random values are similar in all runtime. Is something wrong? Regards Marhamat

 December 4, 2007, 08:26 In Random points(1234567) wh #9 Senior Member   Marhamat Zeinali Join Date: Mar 2009 Location: Tehran, Tehran, iran Posts: 107 Rep Power: 8 In Random points(1234567) what does mean (1234567)?And what does happen when i change 7 to 8? Why? Thanks alot Marhamat

 December 4, 2007, 09:06 I guess it is the seed of the #10 Assistant Moderator   Bernhard Gschaider Join Date: Mar 2009 Posts: 3,915 Rep Power: 40 I guess it is the seed of the (pseudo)random sequence of numbers that is produced by the random-number-generator. By changing it you get a different sequence. But by fixing the seed you make sure that every simulation runs with the same sequence thus making the results reproducible. __________________ Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request

 December 5, 2007, 09:15 Thanks alot Bernhard I want t #11 Senior Member   Marhamat Zeinali Join Date: Mar 2009 Location: Tehran, Tehran, iran Posts: 107 Rep Power: 8 Thanks alot Bernhard I want to use different sequence in different time steps;So i think i must change the number or arrangement of digits in Random points(1234567). After testing some case,for example: Random points(1234567); Random points(1234568); Random points(1434568); Random points(1111); Random points(3); I get different sequance. But i don't know the governing rules that change random sequence of numbers by changing the number or arrangement of digits. Q1)What Does mean the number or arrangement of these digits? Q2)How do i controll random-number-generator for producing different sequence in different time steps? Is any references available in this field? Please explan me more details. With kind regards Marhamat

 December 5, 2007, 13:59 A random number generator gene #12 Assistant Moderator   Bernhard Gschaider Join Date: Mar 2009 Posts: 3,915 Rep Power: 40 A random number generator generates a "pseudo"-random number from the previous number. The number you give to the constructor is the start of the sequence (the predescessor of your first random number) Have a look at http://en.wikipedia.org/wiki/Random_number_generator or "The Art of computer programming" Volume 2 by Donald E. Knuth (http://en.wikipedia.org/wiki/The_Art...er_Programming) if you REALLY want to know it in detail __________________ Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request

 January 30, 2013, 16:59 #13 Senior Member   Mahdi Hosseinali Join Date: Apr 2009 Posts: 124 Rep Power: 8 I have a problem with this Random class, I pass the seed 0 which should make random numbers on each run but the numbers are getting repeated!!! How should I force it to generate different numbers at each run time?

January 31, 2013, 17:30
#14
Assistant Moderator

Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,915
Rep Power: 40
Quote:
 Originally Posted by anishtain4 I have a problem with this Random class, I pass the seed 0 which should make random numbers on each run but the numbers are getting repeated!!! How should I force it to generate different numbers at each run time?
Who says that a seed 0 should give different random sequences?

Just use different seeds if you want different results. The advantage of the behaviour you describe is that results are reproducible. Which is a good thing
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request

 February 3, 2013, 07:49 #15 Senior Member   Mahdi Hosseinali Join Date: Apr 2009 Posts: 124 Rep Power: 8 Guess I read it somewhere that I can't remember it. By looking at Random.C I understand you are right, but what should I do if I want to have different seeds at every run automatically? I want to make a statistical study and changing the seed manually does not look so helpful.

February 3, 2013, 09:45
#16
Assistant Moderator

Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,915
Rep Power: 40
Quote:
 Originally Posted by anishtain4 Guess I read it somewhere that I can't remember it. By looking at Random.C I understand you are right, but what should I do if I want to have different seeds at every run automatically? I want to make a statistical study and changing the seed manually does not look so helpful.
The way non-scientific libraries do it when no seed is provided: the get the current time via the time()-function (see "man 3 time") and use it as a seed.

OR you read the seed from a dictionary. That dictionary is manipulated with a script that changes the seed ... using a pseudo-random value ... that has a fixed seed. That way you have a statistical study ... that is reproducible
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are On Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post Hao CFX 0 September 25, 2008 10:04 Colin FLUENT 0 June 25, 2004 09:59 Colin FLUENT 0 June 24, 2004 23:49 Linfeng Main CFD Forum 0 March 10, 2004 05:49 RajaniKumar Main CFD Forum 13 December 17, 2001 15:25

All times are GMT -4. The time now is 23:53.

 Contact Us - CFD Online - Top