Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Random Words
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
fabulos




PostPosted: Sat Jan 22, 2005 2:15 pm   Post subject: Random Words

how do i pick random words from a list of words? like

Helo
Bye
Good Day
Good Bye


thx
Sponsor
Sponsor
Sponsor
sponsor
xHoly-Divinity




PostPosted: Sat Jan 22, 2005 2:24 pm   Post subject: (No subject)

Firstly you must use randint. It would end up looking something like this...

code:

var x : int
randint (x, 1, 4)
if x = 1 then
    put "hello"
elsif x = 2 then
    put "Bye"
elsif x = 3 then
    put "Good day"
elsif x = 4 then
    put "Good bye"
end if
Neo




PostPosted: Sat Jan 22, 2005 2:28 pm   Post subject: (No subject)

Store your words in an array and call them using Rand.Int.

code:

var word : array 1 .. 4 of string := init ("Hello", "Bye", "GoodBye", "GoodDay")
put word (Rand.Int (1, 4))
basketball4ever




PostPosted: Sat Jan 22, 2005 3:03 pm   Post subject: (No subject)

If you dont like using arrays : P like myself cos i'm strange...
you can always use case

works just like an if statement... but IMO better...
store all of em as
word1
word2
word3
word4
then rand em
SuperGenius




PostPosted: Sat Jan 22, 2005 4:07 pm   Post subject: (No subject)

basketball4ever wrote:
If you dont like using arrays : P like myself cos i'm strange...
you can always use case

works just like an if statement... but IMO better...
store all of em as
word1
word2
word3
word4
then rand em


don't listen. This is terrible form.
MysticVegeta




PostPosted: Sat Jan 22, 2005 8:36 pm   Post subject: (No subject)

I agree, if you can do a random word using 2 lines of code and between unlimited words then why use a case?
person




PostPosted: Sun Jan 23, 2005 11:28 am   Post subject: (No subject)

i agree with "SuperGenius" and "Mystic Vegeta", arrays are so much better than unlimited number of codes Very Happy
MysticVegeta




PostPosted: Wed Jan 26, 2005 7:02 pm   Post subject: Re: Random Words

fabulos wrote:
how do i pick random words from a list of words? like

Helo
Bye
Good Day
Good Bye


thx


Here is the code :
code:
var words : array 1 .. 4 of string := init ("hello", "Hi", "Bye", "GoodBye")
put words (Rand.Int (1, 4))

not so hard with arrays now is it, all you gotta do is make the array to 1..(whatever number u wish) and insert the same amount of strings separated by spaces in the array. Then, edit the Rand.Int formula to 1, (the number of strings you chose)
Sponsor
Sponsor
Sponsor
sponsor
fabulos




PostPosted: Fri Jan 28, 2005 7:25 pm   Post subject: (No subject)

wow...thanks so much!!!...

this'll help me a lot for my french exam..lol

thx again
DarkBlazer




PostPosted: Sat Jan 29, 2005 9:12 am   Post subject: (No subject)

lol.... w/e just wanted to say case isnt good example for this problem (been there done that)
mike200015




PostPosted: Sun Jan 30, 2005 1:35 pm   Post subject: (No subject)

how would you use that type of thing, but say you wanted to use 50 words?
would you have to still use :=init (.....) and set what all the words are?
basketball4ever




PostPosted: Sun Jan 30, 2005 1:39 pm   Post subject: (No subject)

mike200015 wrote:
how would you use that type of thing, but say you wanted to use 50 words?
would you have to still use :=init (.....) and set what all the words are?



unless you're importing a text file... yes you would have to do that.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 12 Posts ]
Jump to:   


Style:  
Search: