Very new to the site and javascript so. Been looking in the forum for a while but couldn't find the answer I was looking for, or at least couldn't understand the threads I'd read.
I'm tryng to make a generator to create as many combinations as needed of the arrays above without repeating the combination and using only one item of each array per iteration. There are also a few extra needs I'd add such as an unique id for the iteration and an extra property to mark the iterations where all the properties have the same value.
This is the code
var accesories = ["pijama" , "urban" , "joker" , "joyboy" , "crypto"];
var hats = accesories;
var tshirts = accesories;
var boots = accesories;
var cards = [];
function randomizeParts() {
model.accesories = accesories[Math.floor(Math.random() * 5)];
model.hats = hats[Math.floor(Math.random() * 5)];
model.tshirts = tshirts[Math.floor(Math.random() * 5)];
model.boots = boots[Math.floor(Math.random() * 5)];
};
function addInsomnio (quantity) {
for (let i = 1 ; i <= quantity ; i++){
model = {
id : 0,
accesories: 0,
hats: 0,
tshirts: 0,
boots: 0}
//adding four digits id
i < 10 ? model.id = '000' + i : i < 100 ? model.id = '00' + i : i < 1000 ? model.id = '0' + i : i <= 10000 ? model.id = i :false;
//randomizing parts
randomizeParts()
//checking if rarity was generated
model.accesories === model.hats && model.accesories === model.tshirts && model.accesories === model.boots ? model.rarity = "original" : false;
//checking its unique
// ????
//Pushing a beautifull brand new and unique card
cards.push(model);
}
};
is there a way to compare the random model to the existing objects in cards before pushing and so randomize it again as many times as needed if that combination already exist?
Note: this is planned to be used one time only to generate a 10,000 items json as a support for a photoshop script.
Aucun commentaire:
Enregistrer un commentaire