Computer Science Canada

Random Words

Author:  fabulos [ 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

Author:  xHoly-Divinity [ Sat Jan 22, 2005 2:24 pm ]
Post 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

Author:  Neo [ Sat Jan 22, 2005 2:28 pm ]
Post 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))

Author:  basketball4ever [ Sat Jan 22, 2005 3:03 pm ]
Post 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

Author:  SuperGenius [ Sat Jan 22, 2005 4:07 pm ]
Post 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.

Author:  MysticVegeta [ Sat Jan 22, 2005 8:36 pm ]
Post subject: 

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

Author:  person [ Sun Jan 23, 2005 11:28 am ]
Post subject: 

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

Author:  MysticVegeta [ 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)

Author:  fabulos [ Fri Jan 28, 2005 7:25 pm ]
Post subject: 

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

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

thx again

Author:  DarkBlazer [ Sat Jan 29, 2005 9:12 am ]
Post subject: 

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

Author:  mike200015 [ Sun Jan 30, 2005 1:35 pm ]
Post 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?

Author:  basketball4ever [ Sun Jan 30, 2005 1:39 pm ]
Post 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.


: