CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > General Forums > Main CFD Forum

problem with rand()

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 4, 2015, 14:06
Default problem with rand()
  #1
New Member
 
Join Date: Mar 2014
Posts: 21
Rep Power: 12
alisina-s is on a distinguished road
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
alisina-s is offline   Reply With Quote

Old   January 4, 2015, 14:36
Default
  #2
Senior Member
 
Michael Prinkey
Join Date: Mar 2009
Location: Pittsburgh PA
Posts: 363
Rep Power: 25
mprinkey will become famous soon enough
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
mprinkey is offline   Reply With Quote

Old   January 7, 2015, 10:08
Default
  #3
New Member
 
Join Date: Mar 2014
Posts: 21
Rep Power: 12
alisina-s is on a distinguished road
thanks Micheal
now it is working fine
alisina-s is offline   Reply With Quote

Reply


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 Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


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


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