Jump to content

Random decimal number


silversand

Recommended Posts

I'm hoping someone can show me how to get a random decimal number. I've googled and can't find anything that works.

 

I need to find a random number between 1.0 and 10.0

 

I can get a random whole number no problem, but decimals aren't working.

 

When I finally get that working, ideally I'd like to be able to find a random number between two decimals (like above) but also have a small chance of getting a decimal slightly higher than the two given. So, for example, maybe a random decimal between 3.5 and 6.0, but a slight chance of getting 6.2?

 

Thank you very much for any help!

Link to comment
https://forums.phpfreaks.com/topic/232069-random-decimal-number/
Share on other sites

What happens if you display the query; is the decimal still there? Note that you may need to modify the code a little:

 

<?php
...

$sql = "INSERT INTO ".$prefix."owned VALUES ('',  '$d[$i]', '$name[$i]','$loggedinname','0','0','0','0','0','0','0', '$code',  '','$alts','ftrade','no','$gend','$headgenes')";

echo $sql;

mysql_query($sql);

...
?>

Wait! Just did it again and there IS a decimal there when I echo it.

 

This is what came up.

 

INSERT INTO owned VALUES ('', '', '','','0','0','0','0','0','0','0', '2131', '','','ftrade','no','','6.5' )

 

Still doesn't work when I try to use it in the code and display it from the database.

Woohooo! That was it! I didn't have the length/values set correctly. Thank you! Thank you!

 

 

Can I press my luck for my other question? How to get a random decimal between two numbers with a chance of a slightly higher result?  So the result from a number between 2.2 and 7.1 would be something like 5.4, but could possibly be 7.2?

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.