将具有随机唯一数字的数组转换为具有顺序进行数字的数组?

223*_*112 -4 c c# arrays random numbers

假设我有一个包含唯一随机数的数组(其中数字的可能范围很小,为0到20).例如:

[6, 3, 11, 9, 4, 5]
Run Code Online (Sandbox Code Playgroud)

如何将以下数组转换为以下内容:

[3, 0, 5, 4, 1, 2]
Run Code Online (Sandbox Code Playgroud)

第二个数组从0开始,以(array.Length-1)结束,但放置与第一个数组中的数量相关.

如何在C/C++/C#中以有效的方式实现这一点?(对方法更感兴趣)

我举了一个例子.它可以是任何东西:

[7, 10, 0, 19, 50, 33, 45, 100]
[1, 2,  0,  3,  6,  4,  5,   7]
Run Code Online (Sandbox Code Playgroud)

数组A中最小的数字在数组B中为0.数组A中的最大数字是数组B中的(array.Length-1).数组A可以是完全随机的(只是它永远不会包含两个或多个相同的数字),但数组A必须以与数组A中相同的顺序包含从0到array.Length-1)的所有数字.

I4V*_*I4V 9

int[] list1 = new[] { 7, 10, 0, 19, 50, 33, 45, 100 };
var orderedList = list1.OrderBy(x => x).ToList();
int[] list2 = list1.Select(x => orderedList.IndexOf(x)).ToArray();
Run Code Online (Sandbox Code Playgroud)

编辑

Per @ Blorgbeard的要求

int[] list1 = new[] { 6, 3, 11, 9, 4, 5 };

var dict = list1.OrderBy(x => x)
                .Select((i, inx) => new { i, inx })
                .ToDictionary(x => x.i, x => x.inx);

int[] list2 = list1.Select(x => dict[x]).ToArray();
Run Code Online (Sandbox Code Playgroud)