Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Security.Cryptography;
- public class Program
- {
- static int GetRandomNumber(byte max){
- //random generation
- byte[] buffer = new byte[1];
- RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
- rng.GetBytes(buffer);
- return buffer[0]%max;
- }
- static bool[] InitGame(ref int boxIndex, ref int toBeRemovedBox, ref int playerChoice){
- //init the random variables
- boxIndex = GetRandomNumber(3);
- toBeRemovedBox = GetRandomNumber(2);
- playerChoice = GetRandomNumber(3);
- //game init
- bool[] boxes = new bool[3];
- for(int i = 0; i < 3; i++)
- {
- boxes[i] = false;
- }
- boxes[boxIndex] = true;
- return boxes;
- }
- static bool NotChanging(){
- int boxIndex = -1,
- toBeRemovedBox = -1,
- playerChoice = -1;
- bool[] boxes = InitGame(ref boxIndex, ref toBeRemovedBox, ref playerChoice);
- return boxes[playerChoice];
- }
- static bool ChangingEveryTime(){
- int boxIndex = -1,
- toBeRemovedBox = -1,
- playerChoice = -1;
- bool[] boxes = InitGame(ref boxIndex, ref toBeRemovedBox, ref playerChoice);
- return !boxes[playerChoice];
- }
- static bool OnlyChoosingSecondTime(){
- int boxIndex = -1,
- toBeRemovedBox = -1,
- playerChoice = -1;
- bool[] boxes = InitGame(ref boxIndex, ref toBeRemovedBox, ref playerChoice);
- bool[] secondTurnBoxes = new bool[2];
- for(int i = 0, counter = 0; i < 3; i++){
- if(i == toBeRemovedBox) continue;
- secondTurnBoxes[counter++] = boxes[i];
- }
- int secondChoice = GetRandomNumber(2);
- return secondTurnBoxes[secondChoice];
- }
- public static void Main()
- {
- int noChange = 0,
- alwaysChange = 0,
- rechoose = 0;
- int numberOfGames= 10000;
- for(int i = 0; i < numberOfGames; i++){
- if(NotChanging()) noChange++;
- if(ChangingEveryTime()) alwaysChange++;
- if(OnlyChoosingSecondTime()) rechoose++;
- }
- Console.WriteLine("nc: " + noChange.ToString() + " /"+ numberOfGames.ToString() );
- Console.WriteLine("cet: "+ alwaysChange.ToString()+ " /"+ numberOfGames.ToString());
- Console.WriteLine("ocst: "+ rechoose.ToString()+ " /"+ numberOfGames.ToString());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement