Generating a Random Number

For questions about using Classic.

Post » 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

Post » Wed Nov 17, 2010 4:32 am

I think 50+random(50) will do it. I could be wrong though.
Image
B
225
S
27
G
13
Posts: 1,774
Reputation: 18,024

Post » Wed Nov 17, 2010 4:42 am

Sir... You are the man.

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

Post » 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)
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Wed Nov 17, 2010 9:34 am

Ah I forgot about that. Definitely good to know.
Image
B
225
S
27
G
13
Posts: 1,774
Reputation: 18,024


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 6 guests