Computer Science Canada

Randomization

Author:  born130 [ Thu Jun 26, 2003 9:28 pm ]
Post subject:  Randomization

From my earlier topic

I just wanted to know how i could randomize each of left, right, up, down
so that i would not have to make screen after screen.

Thanks

Author:  Dan [ Thu Jun 26, 2003 10:25 pm ]
Post subject: 

not shure what you whont to randomize, but you could make a fuction that picks a random number from one to max # of posaibliteys and then uses ifs or a case thingy for each number to do somting.

random code:

randint ( var i : int, low, high : int )

also need to use randomize at beging of progame so you dont get same random numbers.

Ex of random code:


code:

randomize

var roll : int
var i:int

loop
    randint ( i, 1, 6 )
    put "Rolled ", i
end loop

Author:  born130 [ Thu Jun 26, 2003 10:28 pm ]
Post subject: 

basically i just want it to randomize

three moves out of four

i.e. out of up left right down it would choose 3 of them in a random order

Author:  Tony [ Thu Jun 26, 2003 11:56 pm ]
Post subject: 

so run a loop, and mark those picked, then next time randomly pick from those left (or keep on picking untill you end up with one that is not marked yet)

Author:  Andy [ Fri Jun 27, 2003 9:20 am ]
Post subject: 

basicly what u do is randomly choose one key that u don't want and just keep the rest, here's the code

code:

var keys:array 1..4 of int:=init(200,203,205,208)
var unwantedkey:=keys(Rand.Int(1,4))
var count:=0
var finalkeys:array 1..3 of int
for i:1..4
count+=1
if keys(count)not=unwantedkey then
finalkeys(count):=keys
else
count+=1
end if
end for


: