y := make([]T, len(x))
perm := rand.Perm(len(x))
for i, v := range perm {
y[v] = x[i]
}
for i := range x {
j := rand.Intn(i + 1)
x[i], x[j] = x[j], x[i]
}
for i := len(x) - 1; i > 0; i-- {
j := rand.Intn(i + 1)
x[i], x[j] = x[j], x[i]
}
rand.Shuffle(len(x), func(i, j int) {
x[i], x[j] = x[j], x[i]
})
srand(time(NULL));
for (int i = 0; i < N-1; ++i)
{
int j = rand() % (N-i) + i;
int temp = x[i];
x[i] = x[j];
x[j] = temp;
}
std::random_shuffle(my_collection.begin(), my_collection.end());
private static Random rng = new Random();
public static void Shuffle<T>(this IList<T> list)
{
int n = list.Count;
while (n > 1) {
n--;
int k = rng.Next(n + 1);
T value = list[k];
list[k] = list[n];
list[n] = value;
}
}
var shuffled = x.toList()..shuffle();
[Y||{_,Y} <- lists:sort([ {rand:uniform(), N} || N <- X])].
module M_shuffle
contains
function scramble( number_of_values ) result(array)
integer,intent(in) :: number_of_values
integer,allocatable :: array(:)
array=[(i,i=1,number_of_values)]
n=1; m=number_of_values
do k=1,2
do i=1,m
call random_number(u)
j = n + FLOOR((m+1-n)*u)
itemp=array(j); array(j)=array(i); array(i)=itemp
enddo
enddo
end function scramble
end module M_shuffle
:
use M_shuffle, only : scramble
newlist=list(scramble(size(list))
shuffle x = if length x < 2 then return x else do
i <- System.Random.randomRIO (0, length(x)-1)
r <- shuffle (take i x ++ drop (i+1) x)
return (x!!i : r)
for (var i = x.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = x[j];
x[j] = x[i];
x[i] = temp;
}
val newList = list.shuffled()
function(list)
for i = #list, 2, -1 do
local j = math.random(i)
list[i], list[j] = list[j], list[i]
end
end
shuffled = {}
for i, v in ipairs(x) do
local pos = math.random(1, #shuffled+1)
table.insert(shuffled, pos, v)
end
var Iter,rr: integer;
[...]
for Iter := 0 to high(List) do
begin
rr := random(high(List))+1;
tmp := List[Iter];
List[Iter] := List[rr];
List[rr] := tmp;
end;
@shuffled = shuffle('a', 'b', 'c', 'd', 'e', 'f');
shuffled_list = x.shuffle
let mut rng = thread_rng();
x.shuffle(&mut rng);
let mut rng = StdRng::new().unwrap();
rng.shuffle(&mut x);
val items = List(1, 2, 3, 4, 5)
val shuffledItems = Random.shuffle(items)
(define shuffle
(lambda (list)
(if (< (length list) 2)
list
(let ((item (list-ref list (random (length list)))))
(cons item (shuffle (remove item list)))))))
Function Shuffle(Of T)(collection As IEnumerable(Of T)) As List(Of T)
Dim r As Random = New Random()
Shuffle = collection.OrderBy(Function(a) r.Next()).ToList()
End Function