Есть массив и его необходимо заполнить числами в диапазоне к примеру от 1 до 10, в случайном порядке.
На пример в элементе a[1] находится 7, в a[2] находится 4.
// A class that represents an individual card in a playing deck.
public class Card
{
public Suit Suit;
public FaceValue FaceValue;
public override String ToString()
{
return String.Format("{0:F} of {1:F}", this.FaceValue, this.Suit);
}
}
public enum Suit { Hearts, Diamonds, Spades, Clubs };
public enum FaceValue { Ace = 1, Two, Three, Four, Five, Six,
Seven, Eight, Nine, Ten, Jack, Queen,
King };
public class Dealer
{
Random rnd;
// A deck of cards, without Jokers.
Card[] deck = new Card[52];
// Parallel array for sorting cards.
Double[] order = new Double[52];
// A pointer to the next card to deal.
int ptr = 0;
// A flag to indicate the deck is used.
bool mustReshuffle = false;
public Dealer()
{
rnd = new Random();
// Initialize the deck.
int deckCtr = 0;
foreach (var suit in Enum.GetValues(typeof(Suit))) {
foreach (var faceValue in Enum.GetValues(typeof(FaceValue))) {
Card card = new Card();
card.Suit = (Suit) suit;
card.FaceValue = (FaceValue) faceValue;
deck[deckCtr] = card;
deckCtr++;
}
}
for (int i = data.Length − 1; i >= 1; i--)
{
int j = random.Next(i + 1);
// обменять значения data[j] и data[i]
var temp = data[j];
data[j] = data[i];
data[i] = temp;
}