Nu stiu daca am inteles exact ce vrei.
Aici ai un program care genereaza secvente aleatorii de 4 numere, in gama 1-5 :
4 3 5 2
3 4 1 5
3 4 2 1
2 4 3 5
2 5 3 1
2 4 3 1
5 3 1 4
5 2 4 3
Sursa:
Cod:using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Nikita { static class RandomHelper { public static IEnumerable<T> RandomTake<T>( this IEnumerable<T> source, Random rng, int count) { T[] items = source.ToArray(); count = count < items.Length ? count : items.Length; for (int i = items.Length - 1; count-- > 0; i--) { int p = rng.Next(i + 1); yield return items[p]; items[p] = items[i]; } } } class Program { static void Main(string[] args) { Random rnd = new Random(Environment.TickCount); int[] numbers = new int[] { 1, 2, 3, 4, 5}; bool first = true; while (first || Console.ReadKey(true).KeyChar == 'n') { foreach (int number in numbers.RandomTake(rnd, 4)) { Console.Write(number + " "); } first = false; Console.WriteLine("\r\n Press 'n' for next, other key to exit"); } } } }
Release.zip



Răspunde cu citat