C # BCL already has a BST, it is called SortedDictionary<TKey, TValue> , if you do not want Key Value Pairs, but instead want individual elements, you can use SortedSet<T> (SortedSet is in .NET 4.0).
It looks like in your example you will need SortedDictionary<int, WhateverValueType> . Although I donβt know exactly what you need when you say βuniform random choiceβ.
Of course, Dictionary<TKey, TValue> is O (1), which is much faster. Therefore, if you do not need a sorted order of keys, I would use this.
UPDATE . From the sounds of your needs, you will have the efficiency of catch-22. To be able to go into a random continuous index in the data structure, how often will you insert / delete? If not often, you can use an array and just Sort () after (O (n log n)) or always insert / delete in order (O (n)).
Or you can wrap Dictionary<int, YourType> and save the parallel List<int> and update it after each addition / removal:
_dictionary.Add(newIndex, newValue); _indexes.Add(newIndex);
And then just access the random index from the list of search queries. The best part is that in this method the Add () method will be ~ O (1) (unless you change the size of the list, but you can set the initial capacity to avoid some of them), but you will incur the cost of O (n) when deleting.
I am afraid the problem is that you will sacrifice time in the search or delete / insert. The problem is that all the best access time containers are non-contiguous. Together with the double combination List<int>/Dictionary<int, YourValue> you will have a good mix.
UPDATE 2 . It seems like from our continued discussion that if this absolute performance is your requirement, you might be better off if you skip yourself. It was interesting to think about, though, I will update if I think about anything else.