ambiera logo

Ambiera Forum

Discussions, Help and Support.

folder icon Ambiera Forum > CopperCube > Help with CopperCube
forum topic indicator Set shuffle value
person icon
future_k
Registered User
Quote
2024-04-01 00:58:37

Hi am new, do anyone know how to set shuffle value of a variable instead of the random value. (like it will not repeate a value more than once till all value are selected)

person icon
Guest
Guest
Quote
2024-04-01 05:59:19

You would need to use the Execute Java Script action to do this. Here's some code:

var cards = [1, 2, 3, 4, 5]; // Array of cards

// Function to shuffle the cards array randomly
function shuffle(array) {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]]; // Swap elements
}
return array;
}

var shuffled = shuffle(cards); // Shuffled deck

// Function to pick a random card from the deck and remove it
function pickCard(array) {
var randomIndex = Math.floor(Math.random() * array.length); // Get random index
var pickedCard = array.splice(randomIndex, 1)[0]; // Remove and return picked card
return pickedCard;
}

var card = pickCard(shuffled); // Picked card
print(card); // Output picked card

Feel free to ask if you have any questions. Welcome to CopperCube! emoji icon_grin

person icon
future_k
Registered User
Quote
2024-04-01 15:48:56

Thanks bro, i will check the code when i am free


Create reply:










 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


icon_holyicon_cryicon_devilicon_lookicon_grinicon_kissicon_monkeyicon_hmpf
icon_sadicon_happyicon_smileicon_uhicon_blink   






Copyright© Ambiera e.U. all rights reserved.
Contact | Imprint | Products | Privacy Policy | Terms and Conditions |