I have to generate random double number in between 0 and 1. How can i do this using C? I\'ve tried to generate an integer number between 0 and one million and then divide th
Be careful while dividing numbers: when both numbers are integers, the integer division will be used (in this case always resulting in zero).
In order to have a double as a result, you need to force the division to be the division for doubles, which you can achieve by typecasting one of the numbers as a double:
a/b => integer division (when b is larger than a you end up with zero)
((double)a/b) => floating point division (this is what you are looking for)