jeudi 22 septembre 2016

C# Poker Game, Duplication issue [duplicate]

This question already has an answer here:

I'm doing a Poker Game but I've a problem with the random distribution of cards how can i get always a different number from a

for(int i = 0; i <= 4; i++)
{ 
    A = R.Next(1, 53); 
    // Other code
}




Guessing Game in C# where User selects Max value

I have been tasked in my class to create a random number generating guessing game using c# and do/while, if/else loops. This task seems easy enough; however, I am running into problems because I am supposed to start the game by prompting the user to "Enter a max value you want to guess from". I cannot get my program to work properly, as every time I run it, no matter what value I enter it says to "select a value between 1 and 0"

I have attached my exe.

Thanks in advance !!

        Random generator = new Random();
        bool truth = true;
        int MaxRange = Convert.ToInt32(truth); ;
        int userguess = 0;
        int outputnumber = generator.Next(MaxRange);

        do
        {
            Console.WriteLine(" Enter a max number you want to guess from!", MaxRange);
            Console.ReadLine();

            Console.WriteLine("please make a guess between 1 and {0}", outputnumber);

            if (userguess != outputnumber)
            {
                userguess = Convert.ToInt32(Console.Read());

                if (userguess < outputnumber)
                {
                    Console.WriteLine("That is not correct, Guess again");
                    Console.ReadLine();

                }
                if(userguess > outputnumber)
                {

                    Console.WriteLine("That is not correct, Guess again");
                    Console.ReadLine();
                }

                else if (userguess == outputnumber)
                {

 console.writeline("That is correct, the number is {0}, outputnumber);

                }
            }

        } while (truth == false);






        }
    }
}




Prepend a random number to pairs of files

I have in a folder, pairs of files, mp4 and srt subtitle files. e.g. video1.mp4 video1.srt video2.mp4 video2.srt I want to prepend a random number to each video file but I must also prepend the same number to the set file. Does anyone know how I can do this? I'm using a mac, so it could be a bash script, automator, or even PowerShell.




A roll dice returns the same value to both

I built a simple class:

class Die
{
    //Vars

    int number;
    Random R = new Random();

    //Buliding Command

    public Die ()
    {
        number = R.Next(1, 7);
    }

    // Roll
    public void Roll()
    {
         R = new Random();
        number = R.Next(1,7);
    }

    // Get Number

    public int GetNum()
    {
        return number;
    }
}

But whenever I write 2 Dices, it gives the same value to both of them when rolling:

static void Main(string[] args)
{
    Die Dice1 = new Die();
    Die Dice2 = new Die();

    while (Dice1.GetNum() != 6 && Dice2.GetNum() != 6)
    {
        Dice1.Roll();
        Dice2.Roll();
        Console.WriteLine("Dice 1: "+Dice1.GetNum()+"     Dice 2: "+Dice2.GetNum());
    }


    Console.ReadKey();
}

What I get in return is that Dice1 and Dice2 is ALWAYS equal to each other after rolling:

Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 1 Dice 2: 1 Dice 1: 6 Dice 2: 6




select randomly from string array without repetitions

Good day I have some problem regarding selecting a random string from my string array I am currently developing a guessing word game. this is my string array:

 string[] movie = {"deadpool", "batmanvssuperman", "findingdory", "titanic", "suicidesquad", "lordoftherings", "harrypotter", "jurassicpark", "hungergames", "despicableme" };

while this is the process in selecting a random string to my array, what should i do next, because I want to select the string not repeated. e.g when the program starts it will select a string then when i select random string again i want to not select the previous word that i've already selected previously.

string word = movie[r.Next(0, movie.Length)].ToUpper();

Thank you for immediate response! Have a nice day.




Java Random Number with seed changes after a day

I was using the code below to generate random number with seed so that I can generate back the same results next time.

int seed = 100;    
Random rand = new Random(seed);

I manage to get back the same results from the program on the same day, but after a day or two i get a completely different results. Is there a problem of the way I implement the random seed? Anyone encounter this before?




Randomize background image using button onClick event

I want to randomize the background image when the user clicks a button.

Here's what I have.

Every time the button at the bottom right is cliked, I want to randomize the background image from a set array of externally hosted images.

How can I achieve that? (Without PHP, if possible.)