Here's one way to get a random value :
template< typename T >
inline T GetRandomValue( T minval, T maxval )
{
return ( rand() * ( maxval - minval ) / (T) RAND_MAX ) + minval;
}
The random number generator must first be seeded by calling
srand
one time, usually at the beginning of
main
. For a random sequence call it like this :
srand( time( nullptr ) % RAND_MAX );
for a repeatable sequence call
srand
with a constant value, like 47. So after you ask the user how many vertices to use you need to have a for loop and call
GetRandomValue
to get the value to use for each vertex.