![]() |
C# Dice Program Help!!!
I am working on this book that is teaching me C#. I need help with one of the challenges. This is what I have to do: Write a program that simulates a “loaded” die that comes up with the value 1 for half the time and some other random value the other half of the time. All I want is a few hints to get me started.
|
Re: C# Dice Program Help!!!
I'm not sure if this is the simplist way but could make an array with ten members. The first five would be '1', and the rest 2-5. Then run a randomizer to pick an array at random. Maybe something like:
public Random DiceRoller; string Dice[] = { "1","1","1","1","1","2","3","4","5","6"} public string RollDice(); { string DiceValue = Dice[DiceRoller.Next(Dice.Length)]; retrun DiceValue } Not sure if this is what you were looking for or if it helps. |
Re: C# Dice Program Help!!!
Thanks i'll try that when I get home.
|
Re: C# Dice Program Help!!!
I found a better way but thanks for your help. What I did was influence the array for the random instead because you can manipulate it much better. Your idea works but I find this one to be more elegant and easier to read. Thank you anyway.
|
Re: C# Dice Program Help!!!
Code:
//Write a program that simulates a "loaded" die that comes up with the value 1 for half the time |
| All times are GMT +5.5. The time now is 03:40. |