# Generating a Random Number

### » Wed Nov 17, 2010 4:31 am

Hey!

Trying to generate a random number here. I have it working fine except for one condition.

Random(100) gives a number between 0 and 100.

I want it to be a number between say... 50 and 100. How do I go about writing that. I can only get it to be between 0 and x.

Haven't been able to find my answer searching the forums. Anybody know it off hand?
B
3
G
3
Posts: 13
Reputation: 1,201

### » Wed Nov 17, 2010 4:32 am

I think 50+random(50) will do it. I could be wrong though.
B
254
S
32
G
13
Posts: 1,797
Reputation: 19,274

### » Wed Nov 17, 2010 4:42 am

Sir... You are the man.

Worked great thanks.
B
3
G
3
Posts: 13
Reputation: 1,201

### » Wed Nov 17, 2010 4:50 am

random(50) will generate a number between 0 and 49 (including both). The resulting number would be between 50 and 99 (including both). If you need your number to reach 100 sometimes as well, you would need to do 50 + random(51).

(May not be important, but I thought I should mention it)
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,289

### » Wed Nov 17, 2010 9:34 am

Ah I forgot about that. Definitely good to know.
B
254
S
32
G
13
Posts: 1,797
Reputation: 19,274