; NAME: ; ARRAY_SCRAMBLE ; ; PURPOSE: ; This function scrambles array elements to have array elements in new random order ; ; AUTHOR: ; Sangwoo Lee, Ph.D. ; SELab, Inc. ; Seoul, Korea ; Phone: 82-10-3727-1172 ; E-mail: lee@selab.co.kr ; Blog : http//blog.daum.net/swrush ; ; USAGE: ; ARRAY_SCRAMBLE, arr ; ; RETURN VALUE: ; new array in new random order ; ; ARGUMENTS: ; img : input array (any dimension, any size) ; ; Keywords: ; None ; ; MODIFICATION HISTORY: ; First written on Dec 31, 2019. ; ;****************************************************************************************** ; Copyright (c) 2019, by Sangwoo Lee and SELab, Inc. ; ; All rights reserved. ;****************************************************************************************** FUNCTION ARRAY_SCRAMBLE, arr IF arr EQ !null THEN BEGIN PRINT, 'an input array is required!' RETURN, !null ENDIF n = N_ELEMENTS(arr) arr_new = arr inds = INDGEN(n) inds_selected = INTARR(n) REPEAT BEGIN ind = FIX(RANDOMU(seed, 1)*n)<(n-1) IF inds_selected[ind] EQ 1 THEN CONTINUE arr_new[TOTAL(inds_selected)-1] = arr[ind] inds_selected[ind] = 1 ENDREP UNTIL TOTAL(inds_selected) EQ n RETURN, arr_new END