This clip will take a selection of data contained in a comma separated file (without quotes) and reorder those fields in a random fashion.
; take delimited comma separated values ; highlight some of them exclusive of outside ; commas one,*two,three,four*,five,six ; it will then put those values at the end ; the file in random order ; by don at htmlfixit.com ; set list delimiter ^!SetListDelimiter "," ; set array = to selection ^!SetArray %values_current_order%=^$GetSelection$ ; set new array to same ... will change later ^!SetArray %values_new_order%=^$GetSelection$ ; counter to be sure we get all items ^!Set %NA%=0 ; in this loop we get a random item from the array ; and check it to see if we already used it ; if not put it in the new array :Loop ^!Set %random_digit%=^$Calc(RND(^$Calc(^%values_current_order0%-1)$)+1;0)$ ; mark out already used values ^!If "^%values_current_order^%random_digit%%" = "*e*m*p*t*y*" Loop ELSE Process :Process ; build the new array and cycle back for more ; unless done ^!Inc %NA% ^!Set %values_new_order^%NA%%=^%values_current_order^%random_digit%% ^!Set %values_current_order^%random_digit%%=*e*m*p*t*y* ^!If "^%NA%" < "^%values_current_order0%" Loop ELSE Next ^!Jump Doc_End ; you may want to do something else with the output ^!InsertText ^P^P^%values_new_order%^P
Keywords: reorder, random, csv, comma separated value, file
May 29th, 2020 at 9:46 pm
I can tell you have put a lot of work into it. Thank you for this great ideas and for sharing it to your readers.
Kingston Lawyers