0

Hi everyone,

i need to generate random numbers between two values a & b, where both a and b less than 1.

Example

a random number between a = 0.60 and b = 0.69.

what i am trying to do is in C program

temp_ins = a + (drand48())*(b - a + 0.01);

Is the above correct way to generate the random number between values between a and b that are less than 1 but greater than 0.

3
Contributors
3
Replies
5
Views
5 Years
Discussion Span
Last Post by shamusk
-1

#include <time.h>
#include <stdlib.h>

int main ()
{

srand (time(0));
temp_ins = ((rand()%10)+ 60)/100

}

this should get you a new random number between 60-69 every time. Then the number is divided by 100 for example: 68 becomes .68

Edited by SeanTipton: need to learn to read and answer the correct question

Votes + Comments
Entirely wrong. Integer division here always results in 0
0

#include <time.h>
#include <stdlib.h>

int main ()
{

srand (time(0));
temp_ins = ((rand()%10)+ 60)/100

}

this should get you a new random number between 60-69 every time. Then the number is divided by 100 for example: 68 becomes .68

thanks everyone for all the help

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.