
-----------------------------------
golden_thy89
Fri Jun 03, 2005 11:29 am

Need help with randomizing variables
-----------------------------------
Is there a way to do this? :D  :D  :D  :P  :twisted:  8)

-----------------------------------
lyam_kaskade
Fri Jun 03, 2005 11:38 am


-----------------------------------
Sure is.
 var a:int
a:=Rand.Int (1,10)

1 is the lower limit, 10 is the upper limit. Change the parameters to whatever.
Also, there is probably something about this in the tutorials section. Be sure to check it before you post.

-----------------------------------
golden_thy89
Fri Jun 03, 2005 11:40 am


-----------------------------------
what about randomizing various variables, say we were making a blackjack game and we only wanted 2 out of the many various cards to pop up, but they must be randomized, how could we go that.

-----------------------------------
lyam_kaskade
Fri Jun 03, 2005 11:48 am


-----------------------------------
You could put all the cards in an array.


var cards:array 1..52 of int
var card1, card2

for i:1..52
   cards (i):=i
end for

%draw cards
card1:=cards (Rand.Int (1,52))

loop
   card2:=cards (Rand.Int (1,52))
   exit when card2 not= card1
end loop



Hmmm...that's probably giving you too much help.
Oh well. Be sure to check out the walkthrough.
http://www.compsci.ca/v2/viewtopic.php?t=8808

-----------------------------------
golden_thy89
Fri Jun 03, 2005 11:56 am


-----------------------------------
hmmm thanks for the help, but unfortunatly it dosnt work.. for me anyway...

-----------------------------------
lyam_kaskade
Fri Jun 03, 2005 11:58 am


-----------------------------------
Which part doesn't work?

-----------------------------------
golden_thy89
Fri Jun 03, 2005 12:00 pm


-----------------------------------
for some reason the for dosnt work

-----------------------------------
lyam_kaskade
Fri Jun 03, 2005 12:02 pm


-----------------------------------
Oh right.

var cards:array 1..52 of int
var card1, card2:int

for i:1..52
   cards (i):=i
end for

%draw cards
card1:=cards (Rand.Int (1,52))

loop
   card2:=cards (Rand.Int (1,52))
   exit when card2 not= card1
end loop


Though you should have been able to figure that out... Read the tutorials

-----------------------------------
syphon4
Fri Jun 03, 2005 4:01 pm

random things
-----------------------------------
for turing to randomly select something to do the best command to use is the "randint"

-----------------------------------
Cervantes
Fri Jun 03, 2005 5:08 pm


-----------------------------------
The function, Rand.Int(), is much more flexible than the procedure, randint().
