C# Program to Generate Random Even Numbers Using LINQ Parallel Query Last Updated : 28 Nov, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report LINQ is known as Language Integrated Query and was introduced in .NET 3.5. It gives power to .NET languages to generate or create queries to retrieve data from the data source. In this article, we will generate random even numbers in parallel using LINQ. So, we will use ParallelQuery{TSource} to generate a sequence of integral numbers in parallel within the given range. Along with it, we have to use the where and select clause to get the even numbers. Remember that it will throw an ArgumentOutOfRangeException if the stop is less than 0 or start +stop-1 is greater than the MaxValue. Syntax: IEnumerable<int> variable = ((ParallelQuery<int>)ParallelEnumerable.Range(start, stop)).Where(x => x % 2 == 0).Select(i => i);Where the start is the first integer value in the sequence and the stop is the number of sequential integers to generate. Example: Input : Range(start, stop) = Range(1, 20) Output : 2 6 12 16 4 8 14 18 10 20 Input : Range(start, stop) = Range(10, 20) Output : 10 12 14 16 18 20 22 24 26 28Approach: To print even numbers in parallel follow the following steps: Implement a parallelQuery{TSource} and mention the range.Use where clause to check the modulus of y by 2 is equal to zero.Now Select is used to check if the value of the j variable is greater than or equal to the value of the variable(i.e., j).Iterate the even numbers using the foreach loopExample: C# // C# program to generate random even numbers // using LINQ Parallel Query using System; using System.Collections.Generic; using System.Linq; class GFG{ static void Main(string[] args) { // Creating data IEnumerable<int> data = ((ParallelQuery<int>)ParallelEnumerable.Range( // Condition for generating even numbers 10, 20)).Where(i => i % 2 == 0).Select( value => value); // Display even numbers foreach(int even in data) { Console.WriteLine(even); } } } Output: 12 14 16 18 20 22 24 26 28 10 Comment More infoAdvertise with us Next Article C# Program to Generate Numbers that are Multiples of 5 Using the LINQ Parallel Query S saisravanprojects Follow Improve Article Tags : C# C# Programs Similar Reads C# Program to Find the Index of Even Numbers using LINQ Given an array, now our task is to find the index value of the even numbers present in the given array using LINQ. LINQ is known as Language Integrated Query and was introduced in .NET 3.5. It gives the power to .NET languages to generate queries to retrieve data from the data source. So to do this 2 min read C# Program to Generate Odd Numbers in Parallel using LINQ LINQ is known as Language Integrated Query and it is introduced in .NET 3.5. It gives the ability to .NET languages to generate queries to retrieve data from the data source. It removes the mismatch between programming languages and databases and the syntax used to create a query is the same no matt 2 min read C# Program to Generate Numbers that are Multiples of 5 Using the LINQ Parallel Query LINQ is known as Language Integrated Query and it is introduced in .NET 3.5. It gives the ability to .NET languages to generate queries to retrieve data from the data source. It removes the mismatch between programming languages and databases and the syntax used to create a query is the same no matt 2 min read Program to generate a random number between L to R Write a program that generates a random number within a specified range [L, R]. The program should take two integers, L and R, as input and output a random number between L and R (inclusive). Examples: Input: L = 10, R = 20Output: 15 Input: L = -5, R = 5Output: 3 Approach: To solve the problem, foll 2 min read Program to generate a random three digit even number Write a program to generate a random three-digit even number. Examples: Example 1: 482Example 2: 736 Approach: To solve the problem, follow the below idea: We can generate a random three-digit number by generating a random integer first and then modulo it by 900. Now, after modulo with 900, the rema 3 min read Java Program to Generate Random Numbers Using Multiply with Carry Method In computer science, multiply-with-carry (MWC) is a method invented by George Marsaglia for generating sequences of random integers based on an initial set from two to many thousands of randomly chosen seed values. The main advantage of the MWC method is that it invokes simple computer integer arith 2 min read Like