Probability in Eprime 3

103 views
Skip to first unread message

Jacky Kuo

unread,
Sep 29, 2020, 7:38:15 AM9/29/20
to E-Prime
Hi all, I am trying to write probability into Eprime 3 using random number draw since I do not know how to write probability in Eprime 3, would anyone be so kind to see if the following codes would work:

'random number draw to compare against probability later 
g_pop = Random(0, 1000)
c.SetAttrib "Pop", g_pop

'Probability for balloon explosion 
If BalloonSize = 2 Then 
c.SetAttrib "Probability", 0
End If
If BalloonSize = 3 Then 
c.SetAttrib "Probability", 21
End If
If BalloonSize = 4 Then 
c.SetAttrib "Probability", 42
End If
If BalloonSize = 5 Then 
c.SetAttrib "Probability", 63
End If
If BalloonSize = 6 Then 
c.SetAttrib "Probability", 146
End If
If BalloonSize = 7 Then 
c.SetAttrib "Probability", 239
End If
If BalloonSize = 8 Then 
c.SetAttrib "Probability", 313
End If
If BalloonSize = 9 Then 
c.SetAttrib "Probability", 438
End If
If BalloonSize = 10 Then 
c.SetAttrib "Probability", 563
End If
If BalloonSize = 11 Then 
c.SetAttrib "Probability", 688
End If
If BalloonSize = 12 Then 
c.SetAttrib "Probability", 792
End If
If BalloonSize = 13 Then 
c.SetAttrib "Probability", 896
End If
If BalloonSize = 13 And g_pop > c.GetAttrib ("Probability") Then
BoolEndTask = True
End If
If BalloonSize >13 Then 
BoolEndTask = True
End If
ElseIf theResponseData.RESP = "{LEFTARROW}" Then
BoolEndTask = True

End If

'''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''

End If

End If

Loop Until Balloonsize >1 And g_pop <= c.GetAttrib ("Probability") Or BoolEndTask = True

The actual probabilities are:

Balloon size = 3; 2.1%
Balloon size = 4; 4.2%
Balloon size = 5; 6.3%
Balloon size = 6; 14.6%
Balloon size = 7; 23.9%
Balloon size = 8; 31.3%
Balloon size = 9; 43.8%
Balloon size = 10; 56.3%
Balloon size = 11; 68.8%
Balloon size = 12; 79.2%
Balloon size = 13; 89.6%

Because of the decimal point, I am getting Eprime to draw from 1000 instead of 100.; 

Grateful for any suggestions. 

Many thanks 

Chris Broz

unread,
Sep 30, 2020, 10:36:36 AM9/30/20
to E-Prime
Hi,

I spent a little time reading through. I think I'd have a better idea of what's happening here with more of the code. From what I can see, you want to set the probability threshold of EndTask based on Size, but it's not clear to me how Size is being adjusted. Knowing that would help me think through the best way to set/check your EndTask.  For now, it seems like the task can only end at Size>=13.

Is "Loop Until" functional? I've seen that syntax before. If so, that's cool. If not, here's an example of a While loop that you could maybe model after. I adjusted the code to use Else If (which I assume will run faster), and check the probability at every size.

Cheers,
Chris

----

'random number draw to compare against probability later
g_pop = Random(0, 1000)   'Rand number
c.SetAttrib "Pop", g_pop  'Make global
 
'Set probability for balloon explosion based pm soze
If BalloonSize = 2 Then
c.SetAttrib "Probability", 0
Else If BalloonSize = 3 Then
c.SetAttrib "Probability", 21
Else If BalloonSize = 4 Then
c.SetAttrib "Probability", 42
Else If BalloonSize = 5 Then
c.SetAttrib "Probability", 63
Else If BalloonSize = 6 Then
c.SetAttrib "Probability", 146
Else If BalloonSize = 7 Then
c.SetAttrib "Probability", 239
Else If BalloonSize = 8 Then
c.SetAttrib "Probability", 313
Else If BalloonSize = 9 Then
c.SetAttrib "Probability", 438
Else If BalloonSize = 10 Then
c.SetAttrib "Probability", 563
Else If BalloonSize = 11 Then
c.SetAttrib "Probability", 688
Else If BalloonSize = 12 Then
c.SetAttrib "Probability", 792
Else If BalloonSize = 13 Then
c.SetAttrib "Probability", 896
End If

'Check rand against probability. If prob greater, If Size>13, if resp left, EndTask
If BalloonSize > 13 Or g_pop > c.GetAttrib ("Probability") Or theResponseData.RESP = "{LEFTARROW}" Then
BoolEndTask = True
End If

' Loop that sends to earlier in Proc If passed check above
Do While BoolEndTask=False 'Not 100% sure about this syntax
  GoTo XXX 'Flag before object that sets Size
Loop   

David McFarlane

unread,
Sep 30, 2020, 11:11:04 AM9/30/20
to e-p...@googlegroups.com
Jacky Kuo apparently left out the beginning "Do" of their "Do ... Loop
Until" structure, which adds some to the confusion. Note that

Do
....
Loop Until <condition>

is the same as

Do
....
Loop While Not(<condition>)

. Alternatively,

Do Until <condition>
....
Loop

and

Do While Not(<condition>)
....
Loop

work identically to each other. The first two forms of Do...Loop above
will always run the loop at least once, while the second two forms may
jump past the loop.

-- David McFarlane


On 2020-09-30 Wed 10:36 AM, Chris Broz wrote:
> Hi,
>
> I spent a little time reading through. I think I'd have a better idea of
> what's happening here with more of the code. From what I can see, you want
> to set the probability threshold of EndTask based on Size, but it's not
> clear to me how Size is being adjusted. Knowing that would help me think
> through the best way to set/check your EndTask. For now, it seems like the
> task can only end at Size>=13.
>
> Is "Loop Until" functional? I've seen that syntax before. If so, that's
> cool. If not, here's an example of a While loop
> <https://urldefense.com/v3/__https://support.pstnet.com/hc/en-us/articles/360005438974-INFO-Use-of-IsPending-to-execute-script-while-a-response-object-is-running-18034-__;!!HXCxUKc!jz3uHt2k5O1KDHaY7F5od7DuCYc4WvZXBABjaWks35kKEGf3vAToVXA4Xp3CITxw$ > that
Reply all
Reply to author
Forward
0 new messages