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.

Recommended Answers

All 3 Replies

#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

commented: Entirely wrong. Integer division here always results in 0 -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

thanks everyone for all the help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.