how to get the value from the array randomly

72 views
Skip to first unread message

sihua xu

unread,
Nov 7, 2013, 9:15:18 PM11/7/13
to e-p...@googlegroups.com
Hello everyone 

  I know how to define the array with the help of David and sally, and I get the value randomly according to way that they told me, but actually,  I found the program do not get the value of the array randomly and i do not know the reason.
I want to achieve the purpose of the following
 to get one value from each array and decide to end or continue the program by comparing the size of the value from the two arrays. the script example  just as follows
dim a(1 to 4) as integer
dim b (1 to 3) as integer
dim c as integer
dim d as integer
dim randompik as integer
a(1) = 6
a(2) = 3
a(3) = 7
a(4) = 2
b(1) = 2
b(2)= 6
b(3) = 4
c = random(a(1), a(4))
d = random(b(1), b(3))
if c>d then 
 randompik = 1
else randompik =2
end if

I would be grateful if anybody could help me to find the reason why it can not achieve my purpose and modify that
thanks
Sihua Xu

sihua xu

unread,
Nov 7, 2013, 10:01:58 PM11/7/13
to e-p...@googlegroups.com
Sihua Xu

gorgeous yayuan geng

unread,
Nov 7, 2013, 10:21:48 PM11/7/13
to e-p...@googlegroups.com
Dear Sihua,

c = random(a(1), a(4)) . I think this code is the reason. You originally want to get a random number from 6,3,7,2,which is in the array a, but your code is to select a value randomly from 6 to 2, which means you get a random value from 2,3,4,5,6. and I wonder if you can successfully complie the code since random function needs the first parameter as min, the second parameter as max.
so I would recommend that you get a random value from 1,2,3,4 .I'd better give you codes:
t=random(1,4)
c=a(t);
s=random(1,3)
d=b(s)

 


2013/11/8 sihua xu <xusi...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "E-Prime" group.
To unsubscribe from this group and stop receiving emails from it, send an email to e-prime+u...@googlegroups.com.
To post to this group, send email to e-p...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/e-prime/CAPEBGuZKEQU9_P_o67iyLcPMhvy%2BYiMOQYVExDW27EXVKh2aGQ%40mail.gmail.com.

For more options, visit https://groups.google.com/groups/opt_out.

David McFarlane

unread,
Nov 8, 2013, 9:54:26 AM11/8/13
to e-p...@googlegroups.com
I will just add that you can find documentation for the random()
function in the E-Basic Help facility.

-- David McFarlane


At 11/7/2013 10:21 PM Thursday, gorgeous yayuan geng wrote:
>Dear Sihua,
>
>c = random(a(1), a(4)) . I think this code is the reason. You
>originally want to get a random number from 6,3,7,2,which is in the
>array a, but your code is to select a value randomly from 6 to 2,
>which means you get a random value from 2,3,4,5,6. and I wonder if
>you can successfully complie the code since random function needs
>the first parameter as min, the second parameter as max.
>so I would recommend that you get a random value from 1,2,3,4 .I'd
>better give you codes:
>t=random(1,4)
>c=a(t);
>s=random(1,3)
>d=b(s)
>
>
>
>
>2013/11/8 sihua xu <<mailto:xusi...@gmail.com>xusi...@gmail.com>
Reply all
Reply to author
Forward
0 new messages