|
-
Feb 15th, 2005, 09:02 PM
#1
Thread Starter
Hyperactive Member
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 
-
Feb 15th, 2005, 09:19 PM
#2
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
-
Feb 15th, 2005, 11:32 PM
#3
Thread Starter
Hyperactive Member
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 
-
Feb 15th, 2005, 11:41 PM
#4
Thread Starter
Hyperactive Member
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 
-
Feb 15th, 2005, 11:49 PM
#5
Re: More Random Numbers!
VB Code:
Module Module1
Sub Main()
Do
Console.WriteLine(New String("="c, 15))
DisplayRandomNumbers()
Console.WriteLine(New String("="c, 15))
Console.WriteLine("Type 'Exit' to quit, any other key to continue!")
Loop While Not Console.ReadLine.ToLower = "exit"
Console.WriteLine("Exiting... bye!")
End Sub
Private Sub DisplayRandomNumbers()
Dim R As New Random ' if you have 10 here it will always display the same numbers
For I As Integer = 1 To 10
Console.WriteLine(String.Format("Random Number {0}: {1}", I, R.Next(1, 11))) ' you need to speifiy the range here
Next
End Sub
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
-
Feb 16th, 2005, 12:12 AM
#6
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|