master82 Posted January 3, 2007 Share Posted January 3, 2007 I have tried to use:rand(0.98,1.02);to generate a random number between 0.98 and 1.02,these will then be used to add/remove a random 2% off a value ($value = $value1*[random])However, upon printing the random value it is always 0.Any was to generate working small numbers? or maybe you know another way to randomly add/subtract 2% from a value? Link to comment https://forums.phpfreaks.com/topic/32732-solved-small-random-numbers/ Share on other sites More sharing options...
Jessica Posted January 3, 2007 Share Posted January 3, 2007 $value = $value-($value*.02); Link to comment https://forums.phpfreaks.com/topic/32732-solved-small-random-numbers/#findComment-152360 Share on other sites More sharing options...
master82 Posted January 3, 2007 Author Share Posted January 3, 2007 wont that always take off 2%?I need a random amount added or subtracted... to a max of 2% either way Link to comment https://forums.phpfreaks.com/topic/32732-solved-small-random-numbers/#findComment-152367 Share on other sites More sharing options...
Jessica Posted January 3, 2007 Share Posted January 3, 2007 Oh sorry.$num = rand(0,1);if($num){ $value = $value-($value*.02);}else{ $value = $value+($value*.02);}Is that what you mean? Link to comment https://forums.phpfreaks.com/topic/32732-solved-small-random-numbers/#findComment-152373 Share on other sites More sharing options...
master82 Posted January 3, 2007 Author Share Posted January 3, 2007 Ill use that if we cant generate a random percentage...aww silly me... basic maths - should just do rand(98,102)/1000 ot 10000 and multiply that random percentage with the value!If it dont work ill be back lolThanks! Link to comment https://forums.phpfreaks.com/topic/32732-solved-small-random-numbers/#findComment-152381 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.