Author Topic: Randomization  (Read 1043 times)

How would I get a script to call a random function. I was thinking getrandom(function1 , function2 , function3) or something like that.

switch(getrandom(1,3))
{
case1:
lalalala;
break;
case2:
lalalala;
break;
case3:
lalalala;
break;
}

that would call a random lalalala, #1-3

Code: [Select]
switch(getrandom(1, 3)) {
case 1:
function1(%blah);
case 2:
function2(%blah);
case 3:
function3(%blah);
}

Why did you put breaks in there, phflack? You also forgot spaces in the case areas and such. Not that you aren't smart, but keep that in mind. :)

I was hoping on making some more common than the other.
Code: [Select]
function Function()
{
if(getRandom(1,10) >= 7)
{
Common()
}
if(getRandom(1,10) <= 8)
{
LessCommon()
}
if(getRandom(1,10) == 10)
{
BarelyCommon()
}
}
But that would call multiple. How would I make it so after one returned true it stopped there?

I was hoping on making some more common than the other.
Code: [Select]
function Function()
{
if(getRandom(1,10) >= 7)
{
Common()
}
if(getRandom(1,10) <= 8)
{
LessCommon()
}
if(getRandom(1,10) == 10)
{
BarelyCommon()
}
}
But that would call multiple. How would I make it so after one returned true it stopped there?

Do this

Code: [Select]
function Function()
{
%r = getRandom(1,10);
if(%r == 10)
{
BarelyCommon()
}
else if(%r <= 7)
{
Common()
}
else if(%r >= 8)
{
LessCommon()
}
}

The problems in yours include:
10's if would never get called from the bottom.
Wrong < and >
Lacking else, which only calls one of the ifs.
And it's getting a new random number for each if statement.

Code: [Select]
switch(getrandom(1, 3)) {
case 1:
function1(%blah);
case 2:
function2(%blah);
case 3:
function3(%blah);
}

Why did you put breaks in there, phflack? You also forgot spaces in the case areas and such. Not that you aren't smart, but keep that in mind. :)
oops about the spaces, but the break; is needed i thought, at least in C++, as it would then continue to the next statements
i figured it was the same, so i added them in my script with the same style, and it worked, so i figured it was the same
I was hoping on making some more common than the other.
Code: [Select]
function Function()
{
if(getRandom(1,10) >= 7)
{
Common()
}
if(getRandom(1,10) <= 8)
{
LessCommon()
}
if(getRandom(1,10) == 10)
{
BarelyCommon()
}
}
But that would call multiple. How would I make it so after one returned true it stopped there?

you're getting a new random number each time

also, is it possible to have like case 1-5 or no?


also, is it possible to have like case 1-5 or no?
No and I already fixed it all and explained why it was broken.

... but the break; is needed i thought, at least in C++, as it would then continue to the next statements...

Even if that's true, It's already defined as a certain number. Going into the other checks won't make a difference since it isn't those numbers.

Even if that's true, It's already defined as a certain number. Going into the other checks won't make a difference since it isn't those numbers.
Right, but in Java and C++ it would do all of the ones that came after it.
It's silly, but it really happens.
So i get why he said that and i don't know if the same applies to Torquescript.
I guess so.