SieRobin Posted November 7, 2006 Share Posted November 7, 2006 Ok, so I'm trying to figure this out.. everytime you use rand for a random number, it'll never output a decimal number if the parameters contain say..[code]rand(1.6, 10.2);[/code]It'll never output a decimal, I'd just like to know if there's a way to output random numbers with decimals. Link to comment https://forums.phpfreaks.com/topic/26466-decimals-with-rand/ Share on other sites More sharing options...
Orio Posted November 7, 2006 Share Posted November 7, 2006 round(rand(1.6, 10.2));:)Orio. Link to comment https://forums.phpfreaks.com/topic/26466-decimals-with-rand/#findComment-121029 Share on other sites More sharing options...
SieRobin Posted November 7, 2006 Author Share Posted November 7, 2006 Already tried that, doesn't work. You can't round a number that's not a decimal. When the random number is chosen, it's a whole number, not a decimal, therefore you're rounding nothing. Link to comment https://forums.phpfreaks.com/topic/26466-decimals-with-rand/#findComment-121033 Share on other sites More sharing options...
doni49 Posted November 7, 2006 Share Posted November 7, 2006 Move the decimal place so that rand THINKS it's a whole number, then divide by 10 and round it as needed:$rnd_dec = round(rand(16, 102)/10, 1); Link to comment https://forums.phpfreaks.com/topic/26466-decimals-with-rand/#findComment-121058 Share on other sites More sharing options...
SieRobin Posted November 7, 2006 Author Share Posted November 7, 2006 Brilliant idea doni :] works like a charm. Link to comment https://forums.phpfreaks.com/topic/26466-decimals-with-rand/#findComment-121067 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.