Super random

Non-platform specific questions.

Super random

Postby Zehper48 » Mon Sep 17, 2007 7:22 pm

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
I like score
User avatar
Zehper48
 
Posts: 241
Joined: Sun Jun 11, 2006 1:34 am
Location: Advanced Noob
Score: 4 Give a positive score

Re: Super random

Postby metal_pt » Mon Sep 17, 2007 11:00 pm

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;
]v[eta[_ - Using GE since June, 15 2007
Currently using v1.3.8 Registered
metal_pt
 
Posts: 117
Joined: Sat Jun 16, 2007 12:57 pm
Location: Sintra, Portugal
Score: 2 Give a positive score

Re: Super random

Postby Zehper48 » Fri Sep 21, 2007 8:30 pm

Ok but is there a way to make it random with percents?
I like score
User avatar
Zehper48
 
Posts: 241
Joined: Sun Jun 11, 2006 1:34 am
Location: Advanced Noob
Score: 4 Give a positive score

Re: Super random

Postby pixelpoop » Fri Sep 21, 2007 9:14 pm

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
}
User avatar
pixelpoop
 
Posts: 276
Joined: Tue Aug 29, 2006 9:32 pm
Score: 28 Give a positive score

Re: Super random

Postby Zehper48 » Sat Sep 22, 2007 7:01 am

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"?
I like score
User avatar
Zehper48
 
Posts: 241
Joined: Sun Jun 11, 2006 1:34 am
Location: Advanced Noob
Score: 4 Give a positive score

Re: Super random

Postby pixelpoop » Sat Sep 22, 2007 3:39 pm

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".
User avatar
pixelpoop
 
Posts: 276
Joined: Tue Aug 29, 2006 9:32 pm
Score: 28 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron