Computer Science Canada

Help with making a random sequence of numbers 1-26

Author:  hersheychocolates [ Mon Jan 18, 2010 5:59 pm ]
Post subject:  Help with making a random sequence of numbers 1-26

hey everyone
So here is a code that will put 26 numbers (all ranging from 1-26)

var i:int
var number : array 1 .. 26 of int
for counter1: 1..26
randint (i,1,26)
put i
end for

now what i was wondering is how we can make the program put 26 numbers, each ranging from 1-26 but not repeat a number that it has already previously generated! in other words, how can i make it so that it puts 1-26 in a random sequence?
thanks alot in advance!

Author:  Turing_Gamer [ Mon Jan 18, 2010 6:13 pm ]
Post subject:  Re: Help with making a random sequence of numbers 1-26

I would do this
Turing:
for i : 1 .. 26
    loop
        num (i) := Rand.Int (1, 26)
        for j: 1 .. i - 1
            check := num (k) = num (i)
        end for
        exit when check = false
        check := false % Reset if failed
    end loop
end for

Author:  hersheychocolates [ Mon Jan 18, 2010 6:36 pm ]
Post subject:  RE:Help with making a random sequence of numbers 1-26

that doesnt work!!! it keeps saying you didnt declare num and check!!

Author:  TheGuardian001 [ Mon Jan 18, 2010 6:53 pm ]
Post subject:  Re: Help with making a random sequence of numbers 1-26

they weren't giving you a working program, they were showing you the process so you can make your own...


: