# Random Number Generator Assistance

**URL:** <https://forum.kirupa.com/t/random-number-generator-assistance/328961>\
**Category:** flash\
**Created:** [July 6, 2012, 3:40pm UTC](https://forum.kirupa.com/t/random-number-generator-assistance/328961 "2012-07-06T15:40:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Grady\_Rose](https://avatars.discourse-cdn.com/v4/letter/g/eada6e/32.png) [@Grady\_Rose](https://forum.kirupa.com/u/Grady_Rose)\
**Post date:** [July 6, 2012, 3:40pm UTC](https://forum.kirupa.com/t/random-number-generator-assistance/328961/1 "2012-07-06T15:40:49Z")

</div>

I’m a psychologist designing an experiment to test how quickly subjects are able to discriminate between words. Subjects will indicate whether the words displayed are the same or different by pressing S or D which will load the next pair.

I want to have the program randomly present either two words or the same word twice but am having a hard time with the random number generation. I want the formula to return a 1 or 2 and use conditional logic after that. Here’s the random number formula I’ve been stuck on for a while. Any advice?

function pressDifferent (evt:MouseEvent):void  
{  
{  
if(trace.(Math.floor(Math.random()\*(1+2-1))+1).toString()))==2)  
{  
txtRight.text = btText[a];  
txtLeft.text = btText[a];  
a++;  
}  
else  
{  
txtRight.text = btText[a];  
a++;  
txtLeft.text = btText[a];  
a++;  
scoreResponse;  
}  
}

}
