First, generate a collection of indices that match the criteria:
The way I'd do it is to create a collection containing all valid indexes at the start (i.e. 0 to N-2 to exclude the first and last elements) - Enumerable.Range will do that for you.So if N = 8, and x = 3 then
N = 8: 1 2 3 4 5 6
Then generate a random index in that collection, and remove it and the values one larger and one smaller (if present)
i = 3:
index in original table = 4
1 2 6
Generate a random index again and repeat until x has been met or you can't get another value.
At the end, you can use the values to index into your original collection.
Try it on paper and you'll see what I mean.