Reputation: 107
I want to have a if elseif else if else structure in netlogo but it seems that at the moment it is not working.
ifelse random 100 < 68 [ set HBB-Genes "A,A" ];;68%
[ifelse random 100 < 2 [set HBB-Genes "S,S"] ;;2%
[ifelse random 100 < 15 [set HBB-Genes "A,A"];;15%
[set HBB-Genes "A,A"] ;;15%
]]
I would like to have a 68% chance of occurring the set HBB-Genes with "A,A" and the next one with 2% chance of occurring and so on. If anyone has experience with netlogo and can help it will be much appreciated. Thanks.
Upvotes: 3
Views: 11560
Reputation: 30508
You only want to pick one random number, not several. You can use let
to store the random number so you can refer to it later. So:
let chance random 100
ifelse chance < 68
[ set HBB-Genes "A,A" ]
[ ifelse chance < 70
[ set HBB-Genes "S,S" ]
[ ifelse chance < 85
...
And so on.
Upvotes: 6
Reputation: 107
It can be done in the following way with if statements otherwise the next if statements got the remainder of the chance of occuring.
if geneNumber <= 68
[
set HBB-Genes "A,A"
set color blue
]
if (geneNumber > 68) and (geneNumber <= 83)
[
set HBB-Genes "A,S"
set color green
]
if (geneNumber > 83) and geneNumber <= 98
[
set HBB-Genes "S,A"
set color green
]
if geneNumber > 98
[
set HBB-Genes "S,S"
set color red
]
Upvotes: 1