How can I store data with randint?
Author |
Message |
user23
|
Posted: Thu May 12, 2011 9:47 pm Post subject: How can I store data with randint? |
|
|
So I am trying to store data using random integers with the following code:
loop
randint (x, 1, 100)
randint (y, 1, 200)
if item (x,y) = 0 then
item (x,y) :=1
itemcount := itemcount +1
end if
exit when itemcount = 10
end loop
so using that code, shouldn't x, y in item (x,y) be replaced with the random integers, and then the value of the specific random integers receive the +1? Currently, even using that code, while trying to check the value of (x,y) within a for loop, every single item (x,y) = 1, which I assume is because of that line not storing the data for the random integers, but just the variables? So my question is, how should I change / fix this, so that the values are stored for specific random integers?
Thanks |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
|
|
|
|
user23
|
Posted: Fri May 13, 2011 6:24 am Post subject: Re: How can I store data with randint? |
|
|
item is an array
code: | var item : array 1 .. 100, 1 .. 200 of int |
|
|
|
|
|
|
mirhagk
|
Posted: Fri May 13, 2011 8:41 am Post subject: RE:How can I store data with randint? |
|
|
your checking if the (x,y)th element of item is 0, so is there a case where it isn't 0? |
|
|
|
|
|
tyuo9980
|
Posted: Fri May 13, 2011 8:35 pm Post subject: Re: How can I store data with randint? |
|
|
the problem in your code is that you're just naming the element. you're not actually assigning anything to that element.
for i : 1 .. 10
randint x,1,5
arrayx (i) := x
end for |
|
|
|
|
|
user23
|
Posted: Fri May 13, 2011 9:08 pm Post subject: Re: How can I store data with randint? |
|
|
edit |
|
|
|
|
|
|
|