i want mathematical equation or function to get number between tow number .. for example the two number is 5 and 10 .. when i send 5 make process and return number ex:7 this result will not be repeated .. and when send 8 return ex:10
void main()
{
int from=5,to=10;
for(int a=from;a<=to;a++)
{
int result=gen(from,to,a);
}
}
int gen(int from, int to,int value)
{
//make process with 3 args and return value random and will not be repeated
return result;
}
I use many methods but all of them are stored in memory and I don't want it . like this
void not_good()
{
var ran = Enumerable.Range(from, to).OrderBy(x => Guid.NewGuid());
foreach (int i in ran)
{
}
/////////////////
List<int> listNumbers = new List<int>();
int number;
for (int i = from; i < to; i++)
{
do {
number = rand.Next(from, to);
} while (listNumbers.Contains(number));
listNumbers.Add(number);
}
}
Aucun commentaire:
Enregistrer un commentaire