# How can I create a list of random integer numbers with no two equal?

Juan Carlos Ponce Campuzano shared this question 3 years ago

Hello everyone,

I know it is possible to create a list of random integer numbers with no two equal, but I have no idea how to do it.

Any suggestions will be appreciated.

Thanks. With the Shuffle(<List>) you can do nice things. E.g. if you want to have 5 random but no equal numbers from 1 to 20, you can take the first 5 numbers out of the shuffled list of numbers from 1 to 20 with First(Shuffle(Sequence(1, 20)),5).

chris 1

Ok I found a way to do it using JavaScript in the Global JavaScript.

```function generate(){
var arrayContainer = []; // this arrays holds the five random numbers generated;

var genNum = Math.floor(Math.random() * 5) + 1;
arrayContainer.push(genNum);
//console.time();
for (var counter = 1; counter < 5; counter++) {
//the counter is less than five because we already initialise arrayContainer with genNum
var newGen = Math.floor(Math.random() * 5)+1;
while (arrayContainer.lastIndexOf(newGen) !== -1) {
newGen = Math.floor(Math.random() * 5)+1;
}
arrayContainer.push(newGen);
}
//console.timeEnd();
//console.log(arrayContainer);
return arrayContainer;

}```

So with this, I can create the lists like {5, 4, 2, 3, 1}, {2, 5, 1, 4, 3}, ...

Any suggestions how to do it with GGBscripting? 1

With the Shuffle(<List>) you can do nice things. E.g. if you want to have 5 random but no equal numbers from 1 to 20, you can take the first 5 numbers out of the shuffled list of numbers from 1 to 20 with First(Shuffle(Sequence(1, 20)),5).

chris 1

Thanks Chris,

This command is great and also easier to use compare to the JavaScript code.

Regards. 