Quote from
Ronnie on September 3, 2019, 11:39 am
Hi All,
Here's a sample script to shuffle array items... good if you want to create a poker game.. 8))
.Shuffle
SetVar [MaxNum] 82
CreateArray [List1] ""
Loop 1 [MaxNum] [Count]
ArrayAddItem [List1] [Count]
EndLoop
beginJS
Array.prototype.shuffle = function() {
var input = this;
for (var i = input.length-1; i >=0; i--) {
var randomIndex = Math.floor(Math.random()*(i+1));
var itemAtIndex = input[randomIndex];
input[randomIndex] = input[i];
input[i] = itemAtIndex;
}
return input;
}
var tempArray = $rootScope.List1;
tempArray.shuffle();
$rootScope.List1 = tempArray;
endJS
MessageBox "info" "[List1]" "" ""
Hi All,
Here's a sample script to shuffle array items... good if you want to create a poker game.. 8))
.Shuffle
SetVar [MaxNum] 82
CreateArray [List1] ""
Loop 1 [MaxNum] [Count]
ArrayAddItem [List1] [Count]
EndLoop
beginJS
Array.prototype.shuffle = function() {
var input = this;
for (var i = input.length-1; i >=0; i--) {
var randomIndex = Math.floor(Math.random()*(i+1));
var itemAtIndex = input[randomIndex];
input[randomIndex] = input[i];
input[i] = itemAtIndex;
}
return input;
}
var tempArray = $rootScope.List1;
tempArray.shuffle();
$rootScope.List1 = tempArray;
endJS
MessageBox "info" "[List1]" "" ""
luishp has reacted to this post.