-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.hml
54 lines (38 loc) · 1.33 KB
/
test.hml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<html>
<script>
function random_permuatation_no_loops(k) {
var array = new Array(k);
for(var idx = 0; idx < k; idx++)
{
array[idx] = idx;
}
if (k === 1){
return [0];
}
var currentIndex = k - 1 , temporaryValue, randomIndex;
// While there remain elements to shuffle...
while (0 < currentIndex) {
console.log(currentIndex);
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex); // < currentIndex!
if (array[randomIndex] === currentIndex) {
continue;
}
currentIndex -= 1;
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
console.log("swapping);
if (array[0] === 0){
var rand_swap = Math.floor(Math.random() * (k-1)) + 1
array[0] = array[rand_swap];
array[rand_swap] = 0;
}
return array;
}
var f = random_permuatation_no_loops(4);
</script>
<body>
</body>
<html>