Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that creates 10 threads, where each thread creates a data object

ID: 3605331 • Letter: W

Question

Write a program that creates 10 threads, where each thread creates a data object with a random date and a random value associated with it. For different dates you can start with today’s date (a property in the DateTime class in C#) and then keep adding a day for each new thread. For random values, you can use the System.Random class.

After each thread creates its data objects, display the thread id, thread state and the date and values of the data object that the thread created.

Refer to the attached output as an example of how your output should look like. Your output does not have to be exactly like this, but similar.

Explanation / Answer

using System;

public class App {

    public static void Main()

    {

        int seed = 345;

        int min = -44;

        int max = 30;

        Console.WriteLine("Testing 6 random Int32 from 0 to Int32.MAX");

        Random r1 = new Random(seed);

        for (int j = 0; j < 6; j++)

            Console.Write("{0,11} ", r1.Next());

        Console.WriteLine("Testing 6 random int32 from 0 to 30");

        Random r2 = new Random(seed);

        for (int j = 0; j < 6; j++)

            Console.Write("{0,11} ", r2.Next(max));

        Console.WriteLine("Testing 6 random int32 from -44 to 30");

        Random r3 = new Random(seed);

        for (int j = 0; j < 6; j++)

            Console.Write("{0,11} ", r3.Next(min, max));

        Console.WriteLine("Testing 5 random bytes: 0 to 255");

        Random r4 = new Random();

        Byte[] b = new Byte[10];

        r4.NextBytes(b);

        Console.WriteLine("The Random bytes are: ");

        for (int i = 0; i < 10; i++)

        {

            Console.Write(i);

            Console.Write(":");

           Console.WriteLine(b[i]);

        }

        Console.WriteLine("Testing 6 random doubles from 0 to 1");

        Random r5 = new Random(seed);

        for (int j = 0; j < 6; j++)

            Console.WriteLine("{0,11} ",r5.NextDouble());

        Console.WriteLine("Testing 6 random doubles from -44 to 30");

        Random r6 = new Random(seed);

        for (int j = 0; j < 6; j++)

            Console.WriteLine("{0,11}",(min+(max-min)*r6.NextDouble()));

    }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote