Results 1 to 6 of 6

Thread: More Random Numbers!

  1. #1

    Thread Starter
    Hyperactive Member wiccaan's Avatar
    Join Date
    Apr 2004
    Location
    127.0.0.1
    Posts
    475

    Resolved More Random Numbers!

    Hey guys, need a little help with generating some random numbers in a console application.

    First, Im trying to the get the program to generate 10 random numbers between 1 and 10 (Including both 1 and 10) and then display all 10 of them in the console itself on seperate lines.

    Ive tried using the Random function with a loop to display all 10 numbers, but I kept getting numbers way bigger then 10 and it wouldnt loop all 10 numbers only showing 1.

    Thanks in advance to whom ever can help me with this.
    Last edited by wiccaan; Feb 16th, 2005 at 12:12 AM.
    If my post was helpful please rate it

  2. #2
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: More Random Numbers!

    can you post your code?
    kevin
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  3. #3

    Thread Starter
    Hyperactive Member wiccaan's Avatar
    Join Date
    Apr 2004
    Location
    127.0.0.1
    Posts
    475

    Re: More Random Numbers!

    Dispite the fact that I probably did most of it wrong and I didnt save most of it here is what I have left of it:

    Code:
    Module Module1
    
        Sub Main()
            On Error GoTo ErrorHandel
    
            Dim a As String
            Dim b
            Dim R As New Random(10)
            Dim I As Integer = R.Next()
    Begin:
            a = Rnd(I)
    
            Console.WriteLine(a)
            Console.WriteLine(a)
            Console.WriteLine(a)
            Console.WriteLine(a)
            Console.WriteLine(a)
            Console.WriteLine(a)
            Console.WriteLine(a)
            Console.WriteLine(a)
            Console.WriteLine(a)
            Console.WriteLine(a)
    ErrorHandel:
            Console.WriteLine("There was an error! Please press enter!")
            b = Console.ReadLine
            GoTo Begin
        End Sub
    
    End Module
    Like I said, it doesnt work, and its probably completely wrong. Im sorta new to .Net and Im doing this for a science fair project. Thanks in advance.
    If my post was helpful please rate it

  4. #4

    Thread Starter
    Hyperactive Member wiccaan's Avatar
    Join Date
    Apr 2004
    Location
    127.0.0.1
    Posts
    475

    Re: More Random Numbers!

    Well I changed that a little bit instead of making 10 Console.WriteLines Im just using a loop:

    Code:
    For Z = 1 to 10
    Console.Writeline(a)
    Next
    Makes 10 lines automaticly, but the rounding isnt doing 1 to 10 without decimals like I need it to.

    Thanks again in advance.
    If my post was helpful please rate it

  5. #5
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622

    Re: More Random Numbers!

    VB Code:
    1. Module Module1
    2.  
    3.     Sub Main()
    4.  
    5.         Do
    6.             Console.WriteLine(New String("="c, 15))
    7.             DisplayRandomNumbers()
    8.             Console.WriteLine(New String("="c, 15))
    9.             Console.WriteLine("Type 'Exit' to quit, any other key to continue!")
    10.         Loop While Not Console.ReadLine.ToLower = "exit"
    11.  
    12.         Console.WriteLine("Exiting... bye!")
    13.  
    14.  
    15.     End Sub
    16.  
    17.  
    18.     Private Sub DisplayRandomNumbers()
    19.         Dim R As New Random ' if you have 10 here it will always display the same numbers
    20.  
    21.  
    22.         For I As Integer = 1 To 10
    23.             Console.WriteLine(String.Format("Random Number {0}: {1}", I, R.Next(1, 11))) ' you need to speifiy the range here
    24.         Next
    25.     End Sub
    26.  
    27. End Module
    Last edited by <ABX; Feb 15th, 2005 at 11:58 PM.
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  6. #6

    Thread Starter
    Hyperactive Member wiccaan's Avatar
    Join Date
    Apr 2004
    Location
    127.0.0.1
    Posts
    475

    Re: More Random Numbers!

    Awsome thanks alot man. Ill work with this to make it do alot of diffrent things. Thanks again. Helped alot!
    If my post was helpful please rate it

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width