# Rand Help

I’m coding part of my game where the player gets to pick how many children they have and I wanted to input random variable to pick the gender of the children and wasn’t sure how to code it. This is the code I have at the moment.

``````*if numberofchildren = 6
*goto sixchildren
*if numberofchildren = 7
*goto sevenchildren
*if numberofchildren = 8
*goto eightchildren
*label sixchildren
*rand gender 1 2
*if gender = 1
*set gender female
*if gender = 2
*set gender male
*label sevenchildren

*label eightchildren
``````

I’d use a temp variable that then changes the base variables. Like…

Then you’d have to basically copy and paste that code for the number of children, but change the child1 to child2.

You can simplify the logic using a loop, which will allow you to more easily add additional numbers of children if you want to.

All you need to do is create more childgender variables and pick the number of children you would like.

``````*create childgender_1 ""
*create childgender_2 ""
*create childgender_3 ""
*create childgender_4 ""
*create childgender_5 ""
*create childgender_6 ""
*create childgender_7 ""
*create childgender_8 ""
*create currentchild 0

*create numberofchildren 0

*set NumberOfChildren 8

*set currentchild 1
*temp childgender
*label GenderLoop
*if currentchild <= Numberofchildren
*rand childgender 1 2
*if childgender = 1
*set childgender[currentchild] "female"
*if childgender = 2
*set childgender[currentchild] "male"
*set currentchild +1
*goto GenderLoop

\${childgender_1}

\${childgender_2}

\${childgender_3}

\${childgender_4}

\${childgender_5}

\${childgender_6}

\${childgender_7}

\${childgender_8}
``````
2 Likes

Not sure, but I think you want to use *elseif for your middle options and *else for your last if you choose to with your original formatting. @amethyst

1 Like

Thank you that would work as I completely forgot in the start up to set up the number of children so that will fix my problem thanks.

This topic was automatically closed 24 hours after the last reply. If you want to reopen your WiP, contact the moderators.