Click here to Skip to main content
15,909,939 members
Home / Discussions / C#
   

C#

 
AnswerRe: How can i get year, month different from calendar? Pin
Anthony Mushrow28-Aug-11 17:08
professionalAnthony Mushrow28-Aug-11 17:08 
Questionjust woundering about random numbers? Pin
stephen.darling28-Aug-11 12:02
stephen.darling28-Aug-11 12:02 
AnswerRe: Just wondering about random numbers Pin
DaveyM6928-Aug-11 13:06
professionalDaveyM6928-Aug-11 13:06 
JokeRe: just woundering about random numbers? Pin
PIEBALDconsult28-Aug-11 14:10
mvePIEBALDconsult28-Aug-11 14:10 
GeneralRe: just woundering about random numbers? Pin
stephen.darling28-Aug-11 14:57
stephen.darling28-Aug-11 14:57 
GeneralRe: just woundering about random numbers? Pin
PIEBALDconsult28-Aug-11 16:50
mvePIEBALDconsult28-Aug-11 16:50 
AnswerRe: just woundering about random numbers? Pin
ljupcecar28-Aug-11 22:55
ljupcecar28-Aug-11 22:55 
AnswerRe: just woundering about random numbers? [modified] Pin
GParkings1-Sep-11 6:33
GParkings1-Sep-11 6:33 
I'll take a bash at a slightly more realistic roulette simulator.

The roulette wheel works by having the ball travel a spiral path at a random velocity in one direction and the wheel spin at a different random velocity in the opposite direction. The number is determined by the degree of rotation of the wheel at the time the ball reaches a point in the spiral at which it touches the wheel.

Now, since i dont have the inclination to find the mathematical formula for a spiral we are going to assume that the ball is moving in decreasing circles.

we are also going to run the ball and wheel in seperate threads, but i'll leave you to sort out the threading Wink | ;)

Ball thread:

C#
public int RunAndReturnFinalAngle(int startRadius, int wheelRadius)
        {
            Random rng = new Random();
            int sampleCount = 360;
            int currentStep = 1;
            int delayTime = rng.Next(10, 100);
            int currentRadius = startRadius;
            int radiusReduction = rng.Next(1, 5);

            double ballX = 0;
            double ballY = 0;

            int angle = 0;

            while (currentRadius > wheelRadius)
            {
                currentStep++;
                if(currentStep > sampleCount){currentStep = 1;}
                
                //angle of ball from vertical
                angle = 360 * (currentStep / sampleCount);

                //coordinates of ball on circular trajectory
                ballX = currentRadius * Math.Sin(angle);
                ballY = currentRadius * Math.Cos(angle);

                PositionBallGraphic(ballX, ballY);

                //reduce trajectory radius by random ammount - Randomness element 1
                currentRadius -= radiusReduction;
                
                //Sleep random time to give ball a random speed - Randomness element 2
                Thread.Sleep(delayTime);
            }

            return angle;
        }


Now for the wheel, thats a lot simpler, simply run a loop modifying a value between 360 and 0 (remember its going the opposite direction) on a random delay (to set its speed) until the ball thread has done its thing.

At this point you will have the final angle of the ball and the final angle of the wheel.

C#
public int GetNumberIndexForBall(int ballAngle, int wheelAngle)
        {
            int angleRelativeToWheel = ballAngle - wheelAngle;

            //assume 36 numbers on wheel
            return angleRelativeToWheel / 10;

        }


Then you can use that index to get the wheel number from an ordered array/list of numbers on the wheel

Its very rough and hasnt been compiled/tested but that should provide a more real-to-life simulation of roulette than a simple random number between 1 and 36 and also give you graphical positioning data for the ball

modified on Thursday, September 1, 2011 4:12 PM

GeneralRe: just woundering about random numbers? Pin
stephen.darling1-Sep-11 13:45
stephen.darling1-Sep-11 13:45 
GeneralRe: just woundering about random numbers? Pin
GParkings1-Sep-11 21:58
GParkings1-Sep-11 21:58 
GeneralRe: just woundering about random numbers? Pin
stephen.darling2-Sep-11 1:15
stephen.darling2-Sep-11 1:15 
QuestionIs this a good book to learn c#? Pin
stephen.darling28-Aug-11 7:01
stephen.darling28-Aug-11 7:01 
AnswerRe: Is this a good book to learn c#? Pin
Shameel28-Aug-11 8:54
professionalShameel28-Aug-11 8:54 
GeneralRe: Is this a good book to learn c#? Pin
stephen.darling28-Aug-11 11:25
stephen.darling28-Aug-11 11:25 
AnswerRe: Is this a good book to learn c#? Pin
Eddy Vluggen28-Aug-11 9:05
professionalEddy Vluggen28-Aug-11 9:05 
GeneralRe: Is this a good book to learn c#? Pin
stephen.darling28-Aug-11 11:27
stephen.darling28-Aug-11 11:27 
AnswerRe: Is this a good book to learn c#? Pin
BillWoodruff28-Aug-11 19:43
professionalBillWoodruff28-Aug-11 19:43 
Questionintegrate app.config [modified] Pin
Groulien28-Aug-11 4:14
Groulien28-Aug-11 4:14 
AnswerRe: integrate app.config Pin
jschell28-Aug-11 7:49
jschell28-Aug-11 7:49 
QuestionC#.net access Pin
dcof28-Aug-11 3:04
dcof28-Aug-11 3:04 
AnswerRe: C#.net access Pin
PIEBALDconsult28-Aug-11 4:34
mvePIEBALDconsult28-Aug-11 4:34 
GeneralRe: C#.net access Pin
dcof28-Aug-11 8:53
dcof28-Aug-11 8:53 
GeneralRe: C#.net access Pin
PIEBALDconsult28-Aug-11 12:01
mvePIEBALDconsult28-Aug-11 12:01 
GeneralRe: C#.net access Pin
dcof28-Aug-11 13:12
dcof28-Aug-11 13:12 
AnswerRe: C#.net access Pin
jschell28-Aug-11 7:59
jschell28-Aug-11 7:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.