Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var amount = 30;
- var camels = [0,0,0,0,0,0,0,0,0,0,0,0];
- while (amount > 0) {
- var index = Math.floor(Math.random() * camels.length);
- var previous = (camels.length + index - 1) % camels.length;
- var next = (index + 1) % camels.length;
- if (Math.abs(camels[index] + 1 - camels[previous]) <= 1
- && Math.abs(camels[index] + 1 - camels[next]) <= 1) {
- camels[index]++;
- amount--;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement