# How do I randomize between 2 interger within a variable

Get help using Construct 2

### » Sat Apr 26, 2014 2:28 am

this is what i currently have and it's obviously wrong
You do not have the required permissions to view the files attached to this post.
B
5
Posts: 26
Reputation: 283

### » Sat Apr 26, 2014 2:42 am

Not sure I understand you correct. But a variable can only have one value at the time. But if what you mean is that you want this to be either 1 or 2. Then you have to use int(random(2)+1) or you can do choose(1,2) I think, I normally use the first one, due to old habit.
B
45
S
12
G
3
Posts: 1,210
Reputation: 7,559

### » Sat Apr 26, 2014 4:37 am

nimos100 wrote:Not sure I understand you correct. But a variable can only have one value at the time. But if what you mean is that you want this to be either 1 or 2. Then you have to use int(random(2)+1) or you can do choose(1,2) I think, I normally use the first one, due to old habit.

both work quite well thanks =]
B
5
Posts: 26
Reputation: 283

### » Sat Apr 26, 2014 5:29 am

Just a heads up for informatino.

Random generates a float number between X and Y. This includes x.x and y.y. The number always creates a decimal value. So
Random 1,2
1.000000 to 1.9999999
What nimos does is generate a float value of 0.0 to 1.9, then adds + 1 for a solid 1.0 to 2.9.. then uses the int to truncate the decimal value off.
B
94
S
18
G
9
Posts: 2,457
Reputation: 15,177

### » Sat Apr 26, 2014 7:14 am

I was advised to use choose() in preference to random() as the choose() is slightly quicker -obviously this depends on the circumstances. In this case I would use "Choose(1,2)".
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,912

### » Sat Apr 26, 2014 7:43 am

jayderyu wrote:Just a heads up for informatino.

Random generates a float number between X and Y. This includes x.x and y.y. The number always creates a decimal value. So
Random 1,2
1.000000 to 1.9999999
What nimos does is generate a float value of 0.0 to 1.9, then adds + 1 for a solid 1.0 to 2.9.. then uses the int to truncate the decimal value off.

thanks for the extra info. learnt something new
B
5
Posts: 26
Reputation: 283