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
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);

...
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.