|
[Sponsors] |
January 4, 2015, 14:06 |
problem with rand()
|
#1 |
New Member
Join Date: Mar 2014
Posts: 21
Rep Power: 12 |
Hi Everybody
I am using rand function in my solver and somehow I need random numbers between 0 and 6 but the problem is that when I simply use rand() function, I get unexpected huge numbers and these numbers are constant run by run. I have read somewhere in forum that rand(an integer) should work.but in my case I have error. can anyone help me with this? thanks in advance |
|
January 4, 2015, 14:36 |
|
#2 |
Senior Member
Michael Prinkey
Join Date: Mar 2009
Location: Pittsburgh PA
Posts: 363
Rep Power: 25 |
rand() returns an int, so you need to normalize by RAND_MAX and convert to float/double if necessary. And if you don't use srand() to seed the PRNG, you will always get the same sequence.
http://eternallyconfuzzled.com/arts/jsw_art_rand.aspx |
|
January 7, 2015, 10:08 |
|
#3 |
New Member
Join Date: Mar 2014
Posts: 21
Rep Power: 12 |
thanks Micheal
now it is working fine |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
UDF compiling problem | Wouter | Fluent UDF and Scheme Programming | 6 | June 6, 2012 04:43 |
Gambit - meshing over airfoil wrapping (?) problem | JFDC | FLUENT | 1 | July 11, 2011 05:59 |
natural convection problem for a CHT problem | Se-Hee | CFX | 2 | June 10, 2007 06:29 |
Adiabatic and Rotating wall (Convection problem) | ParodDav | CFX | 5 | April 29, 2007 19:13 |
Is this problem well posed? | Thomas P. Abraham | Main CFD Forum | 5 | September 8, 1999 14:52 |