Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Need help with randomizing variables
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)

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.

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...

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

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

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().
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 10 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: