CTJ
CTJ
CC#
Created by TheUnquiet on 2/28/2024 in #help
Random Generator method
static void Main(string[] args)
{
List<int> MyNumbers = new();

while (true)
{
MyNumbers.Add(GenerateNewNumber(MyNumbers, 6));
Console.WriteLine(string.Join(", ", MyNumbers));
}

}


static int GenerateNewNumber(List<int> myList, int MaxInt, int MinInt = 0)
{
List<int> AllNumbers = Enumerable.Range(MinInt, MaxInt).ToList();
AllNumbers.RemoveAll(myList.Contains);

if (AllNumbers.Count == 0)
throw new Exception("No new numbers can be generated in this range.");
//return 0;

return AllNumbers[new Random().Next(AllNumbers.Count())];
}
static void Main(string[] args)
{
List<int> MyNumbers = new();

while (true)
{
MyNumbers.Add(GenerateNewNumber(MyNumbers, 6));
Console.WriteLine(string.Join(", ", MyNumbers));
}

}


static int GenerateNewNumber(List<int> myList, int MaxInt, int MinInt = 0)
{
List<int> AllNumbers = Enumerable.Range(MinInt, MaxInt).ToList();
AllNumbers.RemoveAll(myList.Contains);

if (AllNumbers.Count == 0)
throw new Exception("No new numbers can be generated in this range.");
//return 0;

return AllNumbers[new Random().Next(AllNumbers.Count())];
}
Console output:
4
4, 2
4, 2, 1
4, 2, 1, 5
4, 2, 1, 5, 0
4, 2, 1, 5, 0, 3
4
4, 2
4, 2, 1
4, 2, 1, 5
4, 2, 1, 5, 0
4, 2, 1, 5, 0, 3
and program ends with exception being thrown
58 replies
CC#
Created by TheUnquiet on 2/28/2024 in #help
Random Generator method
yes.
58 replies
CC#
Created by TheUnquiet on 2/28/2024 in #help
Random Generator method
oooooor you could make a list1 with all numbers from 0 to maxint then remove ones that are already on list2 and then pick a random number from that list1 and insert it to your output list2 that way you'd avoid loops altogether
58 replies
CC#
Created by TheUnquiet on 2/28/2024 in #help
Random Generator method
Well I imagined it something like Enter loop Generate random number check if number is in list if yes add and break if loop is repeated more than say 100 times break and do something or alternatively you can build checker to see if every possible number was used yet
58 replies
CC#
Created by TheUnquiet on 2/28/2024 in #help
Random Generator method
and of cousrse add a limiting case so you dont get stuck in the loop forever
58 replies
CC#
Created by TheUnquiet on 2/28/2024 in #help
Random Generator method
its not ideal but you might want to create loop and loop till you find number thats not in list and then break out
58 replies
CC#
Created by CTJ on 8/20/2023 in #help
❔ Cannot convert lambda expression to type 'Activity' because it is not a delegate type error
Yea no problem, I did it by hand then lol
12 replies
CC#
Created by CTJ on 8/20/2023 in #help
❔ Cannot convert lambda expression to type 'Activity' because it is not a delegate type error
12 replies
CC#
Created by CTJ on 8/20/2023 in #help
❔ Cannot convert lambda expression to type 'Activity' because it is not a delegate type error
Are we not closing those anymore?
12 replies
CC#
Created by CTJ on 8/20/2023 in #help
❔ Cannot convert lambda expression to type 'Activity' because it is not a delegate type error
Thanks!
12 replies
CC#
Created by CTJ on 8/20/2023 in #help
❔ Cannot convert lambda expression to type 'Activity' because it is not a delegate type error
I forgot about this one
12 replies
CC#
Created by CTJ on 8/20/2023 in #help
❔ Cannot convert lambda expression to type 'Activity' because it is not a delegate type error
Oh
12 replies
CC#
Created by CTJ on 2/13/2023 in #help
❔ ✅ Equation in code
!close
9 replies
CC#
Created by CTJ on 2/13/2023 in #help
❔ ✅ Equation in code
Oh okay thanks
9 replies
CC#
Created by CTJ on 2/13/2023 in #help
❔ ✅ Equation in code
On side question, what does d do?
9 replies
CC#
Created by CTJ on 2/13/2023 in #help
❔ ✅ Equation in code
That worked, thanks!
9 replies
CC#
Created by CTJ on 8/25/2022 in #help
Publish fail [Answered]
Oh and issue persists on all projects I try to publish
5 replies
CC#
Created by CTJ on 8/25/2022 in #help
Publish fail [Answered]
Any Idea why this would happen and how to solve it?
5 replies
CC#
Created by CTJ on 8/21/2022 in #help
Merge 2 csharp documents in visual studio [Answered]
great, thanks!
12 replies
CC#
Created by CTJ on 8/21/2022 in #help
Merge 2 csharp documents in visual studio [Answered]
Thing is this are litteraly 2 duplicate files not on github, only in my project that have some changes I need to merge
12 replies