RANDOM NUMBER! *REP+*
#1

Hey guys, i need a little help.

I maybe have an idea, how to do it, but not sure, how in terms of scripting. What i need, is for example ten-digit number, which will consist of random numbers. And than these random generated numbers will assign to playerid and if he writes them wrong to the dialog, it will do action, the same as if he writes them right. If one of you guys would be enable to chart me an example of this or explain, what exactly i need to do, i would give him rep+.
Reply
#2

This might help you:

PHP код:
stock GenerateNumber(digits
{
    if(
digits <= 0) return -1;
    new 
number 0;
    while(
digits 1) { 
        
digits -= 1;
        
number += (random(9) + 1) * floatround(floatpower(10digits));
    }
    
number += random(10);
    return 
number;

10-digit numbers may be a problem because of cellmax. There are workarounds though.
Reply
#3

pawn Код:
stock RandomBetween(minimum_value, maximum_value)
{
    return (random(maximum_value - minimum_value) + minimum_value);
}
printf("%d", RandomBetween(1000000000, 9999999999));
Reply
#4

Nice! Thanks guys for help, but for me as newbie, could you guys please explain it a little bit more?

Note: I am not asking for copy/paste code, just for a little more explanation.
Reply
#5

Use on of the functions given above and wherever you need a random number in your code, put RandomBetween/GenerateNumber along with params.

If you need a number between 0-10, just put
pawn Код:
new rNumber = RandomBetween(0,10);
Reply
#6

It's simple to understand with a little common sense.

pawn Код:
(random(maximum_value - minimum_value) + minimum_value)
random - Selects a random number, starting from 0. e.g. random(3), this would select a random number equal or between 0 and 2.
maximum_value - The returned value won't go over this value.
minimum_value - The returned value won't go below this value.

e.g.

RandomBetween(10, 20)

It would return a number equal or between 10 and 20.

minimum_value = 10 - maximum_value = 20

Now (random(maximum_value - minimum_value) + minimum_value) would do the following while respecting the parentheses:

(maximum_value - minimum_value)
20 - 10 = 10

random(10) - e.g. 5

5 + minimum_value

5 + 10 -> 15
Reply
#7

I know it may sound like a troll or something, but i still dont really understand what i need to do, how i need to do it and where to put it.

Can someone be really that kind and actually maybe chart me some example with explanation, so i can really learn from it and make it myself please? I would really appreciate it and REP+ him, couse that is what i need.

Then again i am not asking for whole code, but this guys what you gave me, i just dont understand it, cant explain it more.
Reply
#8

Hey if want to find random of ranges it is like this
random(upper lmit - lower limit+1)+lower limit
Reply
#9

Yes, but than for example how can i work with it? For example add it into some variable and than check, whether player got it right or bad?
Reply
#10

let x be the variable and you want the players to type a ten digit number between 10 and 20
so assign x=random(20-10+1)+10;
or x=random(11)+10;
Now check this with inputext of of your dialog under ondialogresponse
like
Quote:

if(inputext == x)
{
//sendmessage correct
}
else
{
//send wrong message
}

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)