Search code examples
arraysrandomrebol3

Efficient way to fill an array with its own indices in Rebol3


What's a neat one-liner to fill an array (of given possibly dynamic size) with its own indices?

I was trying this:

data: copy {}
repeat tilenum totaltiles [ append data rejoin [tilenum " "] ]

...and then looking to convert it into an array, but there must be a more Rebolish way of doing such a thing, I think.

My end goal is actually to then randomize the order of the array's contents, which I think would be the output of random myarrayhere, but perhaps there's even a way to do all of this in one fell swoop?


Solution

  • If you want random array (block!) why not start with block instead of string in the first place?

    >> random array/initial length: 10 does [-- length]
    == [3 10 7 9 2 5 8 6 1 4]