Random Money
#1

Код:
		  new money;
          money= random(500 to 1000);
I want money random from 500 to 1000
How to do that
Reply
#2

Use this function
PHP код:
randomex(minmax)
{
    return 
random(max-min)+min;

Reply
#3

A better way to explain how you solve it, is to look at the problem part for part.
You want the ranom to start at 500, and end at 1000. Between 500 and 100 you have 500 units.

PHP код:
new money 500//This will make it "always" start at 500
money money random(500); //then, reinitialize the variable. Tell the script that you want 500 + '0-500' more. 
If you want another range, lets say you want a random value between 75-94?

PHP код:
new money 75;
money money random(19); //this will always be 75-94. 
This is also basically what the function posted by "Coool" above does, but in a shorter format. I just thought you wanted to know why it worked.
Reply
#4

Quote:
Originally Posted by denNorske
Посмотреть сообщение
A better way to explain how you solve it, is to look at the problem part for part.
You want the ranom to start at 500, and end at 1000. Between 500 and 100 you have 500 units.

PHP код:
new money 500//This will make it "always" start at 500
money money random(500); //then, reinitialize the variable. Tell the script that you want 500 + '0-500' more. 
If you want another range, lets say you want a random value between 75-94?

PHP код:
new money 75;
money money random(19); //this will always be 75-94. 
This is also basically what the function posted by "Coool" above does, but in a shorter format. I just thought you wanted to know why it worked.
Thank you very much, Solved. <3
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)