Adblock breaks this site

Help with random dice

Discussion in 'Programming General' started by redawsomeness, Jan 15, 2011.

  1. redawsomeness

    redawsomeness Forum Addict
    Banned

    Joined:
    Jul 28, 2010
    Posts:
    614
    Referrals:
    1
    Sythe Gold:
    0
    Help with random dice

    Alright so I was assigned this project in class, but I felt like playing games at the time lol so I decided that I would do it at home for "study material" for the final.

    I have the program built, and its working. But, it won't change the numbers every time, like it's not fully randomized or something. The numbers do change every time I do open and close the program though, but it doesn't change during the same time that the program is open.

    If anybody could help me, it would be great :)

    Here is a quote from the document with all the exercises on it and what he wants us to do on it:
    And then here is my source code:
     
  2. Covey

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816
    Help with random dice

    Your randomize function is correct, it's something in your huge 'IF' statement. But seeing i can't debug while looking at it on the page and i'm too lazy to setup this project myself i can't help you.

    If you want me to help, upload your project to the net and i'll have a look at it then.
     
  3. Covey

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816
    Help with random dice

    Bah i got bored and did it for you lol...

    Do the following:
    1). Open up a new project in VB.NET.
    2). Add a Label called Label1 to your Form.
    3). Add a Button called Button1 to your Form.
    4). Copy and paste the code below to your Button1_Click event:
    Code:
            Dim intDie1 As Integer
            Dim intDie2 As Integer
            Dim intLuckyCount As Integer
            Dim intRollCount As Integer
    
            Do Until intLuckyCount = 100
    
                intRollCount = intRollCount + 1
    
                Randomize()
                intDie1 = Int(Rnd() * 6) + 1
                intDie2 = Int(Rnd() * 6) + 1
    
                If intDie1 + intDie2 = 7 Then
                    intLuckyCount = intLuckyCount + 1
                End If
    
                'You may want to int() +1 the introllcount / intluckycount below so you don't get a decimal number.
                Label1.Text = "1 in " & intRollCount / intLuckyCount & " rolls = 7."
            Loop
    5). Test the project. :D

    Also this is vb.NET not vb6 ;)
     
  4. redawsomeness

    redawsomeness Forum Addict
    Banned

    Joined:
    Jul 28, 2010
    Posts:
    614
    Referrals:
    1
    Sythe Gold:
    0
    Help with random dice

    Thanks! :)

    Also I don't use vb6...I use the Visual Studio 2008 Express Edition because thats what we use in school, but I thought they were the same thing anyway.
     
  5. Covey

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816
    Help with random dice

    No worries dude.
     
< how to compile other .exes into one .exe? | guidence needed with visual basic >


 
 
Adblock breaks this site