Snooble Posted March 3, 2007 Share Posted March 3, 2007 <?php $_SESSION['point'] = rand(0, 10).".". rand(0, 9) rand(0, 9); echo $_SESSION['point']; ?> I want to set a variable (SESSION OR NOT) to a random number. The number needs to be 2 dec places. so i've used 3 random numbers. ????? how can i get it to work? The idea is to add the amount to a mysql cell (easy enough i believe) and then echo the cell out. number should look like this : *.** in the sql table. so: 3.91 or 1.27 etc. Thanks, Snooble Quote Link to comment https://forums.phpfreaks.com/topic/41016-random-number-should-be-easy/ Share on other sites More sharing options...
ted_chou12 Posted March 3, 2007 Share Posted March 3, 2007 rand(0, 10) should also be rand(0, 9) since you want it in the *.** format, and btw, what is your problem? Ted Quote Link to comment https://forums.phpfreaks.com/topic/41016-random-number-should-be-easy/#findComment-198607 Share on other sites More sharing options...
Snooble Posted March 3, 2007 Author Share Posted March 3, 2007 blank page.. parse yes thanks, but i can do that. Just need to set the number to a variable and echo it out. Thanks Snooble Quote Link to comment https://forums.phpfreaks.com/topic/41016-random-number-should-be-easy/#findComment-198610 Share on other sites More sharing options...
ted_chou12 Posted March 3, 2007 Share Posted March 3, 2007 do you have the start session at the top? and try: <?php $_SESSION['point'] = "".rand(0, 10).".".rand(0, 9)."".rand(0, 9).""; echo $_SESSION['point']; ?> instead. Ted Quote Link to comment https://forums.phpfreaks.com/topic/41016-random-number-should-be-easy/#findComment-198611 Share on other sites More sharing options...
Snooble Posted March 3, 2007 Author Share Posted March 3, 2007 lol duh... i didn't have start session at the top, it still gave me a parse, used your code and all works. Thanks, Seem like an expert to me! Keep up the good work! Thanks Snooble Quote Link to comment https://forums.phpfreaks.com/topic/41016-random-number-should-be-easy/#findComment-198612 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.