Generally the way this site works is that you show what you have done, you say what's not working and we go from there.
Seeing your question, there are two possibilities: either you want us to write your code (which I won't do) or you don't have the slightest clue on how to start.
I'll go for the second approach, and give you a starting point on how your question can be handled:
First you create a list, containing all numbers from 1 to 10, and you keep track of the number of elements in that list (call it lSize
). Then you generate a random number between 0 and lSize
(which can be done using random()*lSize
, rounded down). This gives you the index of the number you might take. You take the number, present on that index, in the list, and you remove it from the list.
Let me show you how it works, in an example:
list : (1,2,3,4,5,6,7,8,9,10)
lSize : 10
final_list : <empty>
First iteration : imagine that random()*lSize
, rounded down, equals 3.
list[3] = 4 (generally we start counting at 0)
So you add 4 to your final list (currently this is `final_list=(4)`)
You then remove that index from the list, and you get following values:
list : (1,2,3,5,6,7,8,9,10)
lSize : 9
final_list : (4)
Second iteration: imagine that random()*lSize
, rounded down, equals 8.
list[8] = 10
Remove it and add it to the final_list:
list : (1,2,3,5,6,7,8,9)
lSize : 8
final_list : (4,10)
You continue from there until, either your list is empty or lSize
is zero.
Beware: list
is preferably a linked list instead of an array, as the removal of an element somewhere in the middle should cause the other elements to be shifted. In an array, this is difficult; in a linked list, this is trivial.
Good luck