Page 1 of 1

Super random

PostPosted: Mon Sep 17, 2007 7:22 pm
by Zehper48
Ok i think there is a code but im not good with making variables random
i would like somthing like this on a key down event
60% chance that variable "Number" =0
40% chance that variable "Number" >=1 through variable "attack"

thank you if you can help me =p

Re: Super random

PostPosted: Mon Sep 17, 2007 11:00 pm
by metal_pt
Well, you can try it this way:

Code: Select all
int number;
int rnd=round(rand(5));
if(rnd<=3)
    number=0;
else
    number=1;

Re: Super random

PostPosted: Fri Sep 21, 2007 8:30 pm
by Zehper48
Ok but is there a way to make it random with percents?

Re: Super random

PostPosted: Fri Sep 21, 2007 9:14 pm
by pixelpoop
something like this?

int n;
n=rand(100);
if (n<=60){//code here with a 60% chance
}
if (n>60 && n<=90){//code here with a 30%chance
}

Re: Super random

PostPosted: Sat Sep 22, 2007 7:01 am
by Zehper48
Code: Select all
int n;
n=rand(100);
if (n<=60){damage=0;
}
if (n>60 && n<=90){damage =1through "maxhit";
}

Where i put "damage =1through "maxhit"; is there a way to do that, like randomly pic 1 through the value of my variable called "maxhit"?

Re: Super random

PostPosted: Sat Sep 22, 2007 3:39 pm
by pixelpoop
If "damage" is a variable and "maxhit" is a variable with a value of 50, then "damage" will equal a random number between 1 and 50 in this example.

int n;
n=rand(100);
if (n<=60){damage=0;
}
if (n>60 && n<=90){damage =rand(maxhit)+1;
}

note: The random function includes numbers from 0 and goes up to 1 number short of your maximum number. This is why we have to add 1, so "damage will equal at least 1 and up to "maxhit".