The rand function returns a pseudorandom integer in the range 0 to RAND_MAX. Use the srand function to seed the pseudorandom-number generator before calling rand. 可以 如下写:#define RAND_MAX 10 float MyRand() { srand(RAND_MAX); return static_cast<float>(rand()) / 10.0; }
Math.random Class Overview | Class Members | This Package | All Packages Syntax public static synchronized double random() Returns a pseudorandom double between 0.0 and 1.0. Description Returns a random number between 0.0 and 1.0. Random number generators are often referred to as pseudorandom number generators because the numbers produced tend to repeat themselves after a period of time.
可以 如下写:#define RAND_MAX 10
float MyRand()
{
srand(RAND_MAX);
return static_cast<float>(rand()) / 10.0;
}
Class Overview | Class Members | This Package | All Packages Syntax
public static synchronized double random()
Returns
a pseudorandom double between 0.0 and 1.0.
Description
Returns a random number between 0.0 and 1.0. Random number generators are often referred to as pseudorandom number generators because the numbers produced tend to repeat themselves after a period of time.
#include<time.h>
srand(time(0));
float a=((float)rand())/RAND_MAX;
其中RAND_MAX是已定的产生随机树的最大的.具体可以看看msdn.