Author |
Message |
golden_thy89
|
Posted: Fri Jun 03, 2005 11:29 am Post subject: Need help with randomizing variables |
|
|
Is there a way to do this? 8) |
|
|
|
|
|
Sponsor Sponsor
|
|
|
lyam_kaskade
|
Posted: Fri Jun 03, 2005 11:38 am Post subject: (No subject) |
|
|
Sure is.
code: | 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
|
Posted: Fri Jun 03, 2005 11:40 am Post subject: (No subject) |
|
|
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
|
Posted: Fri Jun 03, 2005 11:48 am Post subject: (No subject) |
|
|
You could put all the cards in an array.
code: |
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
|
Posted: Fri Jun 03, 2005 11:56 am Post subject: (No subject) |
|
|
hmmm thanks for the help, but unfortunatly it dosnt work.. for me anyway... |
|
|
|
|
|
lyam_kaskade
|
Posted: Fri Jun 03, 2005 11:58 am Post subject: (No subject) |
|
|
Which part doesn't work? |
|
|
|
|
|
golden_thy89
|
Posted: Fri Jun 03, 2005 12:00 pm Post subject: (No subject) |
|
|
for some reason the for dosnt work |
|
|
|
|
|
lyam_kaskade
|
Posted: Fri Jun 03, 2005 12:02 pm Post subject: (No subject) |
|
|
Oh right.
code: |
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 |
|
|
|
|
|
Sponsor Sponsor
|
|
|
syphon4
|
Posted: Fri Jun 03, 2005 4:01 pm Post subject: random things |
|
|
for turing to randomly select something to do the best command to use is the "randint" |
|
|
|
|
|
Cervantes
|
Posted: Fri Jun 03, 2005 5:08 pm Post subject: (No subject) |
|
|
The function, Rand.Int(), is much more flexible than the procedure, randint(). |
|
|
|
|
|
|