Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
Hi all, just registered for this.
As a novice Pascal programmer I would like to generate a unique code within Pascal and put it into an array. The code has to exist out of 4 unique numbers ranging from 0 to 9.
It's easy to generate 4 numbers from 0 to 9 with the Random function but the problem is that a number can only be used once. So for example this would be good:
0 5 9 4
This would be wrong:
0 5 0 5
At first I was thinking along the lines of repeating the Random function until it no longer matches another number. That's very easy for the first two:
[code]a := Random(9)
b := Random(9);
UNTIL b <> a;[/code]
But this won't work for c: I can check to see if c is the same as a and if it is then Randomize again, after randomizing it it hopefully is no longer the same as a but then it's the same as b. Randomizing again might make it the same as a again.
c := Random(9);
UNTIL c <> a AND c <> b;[/code]
But that gives me type mismatch. It *could* be possible with nested If's but that would look like a mess.
Anyone have an idea for a simple solution to this?
0 · ·