random number generator

skaryChinezeGuie

Well-known member
Joined
Apr 23, 2006
Messages
94
Programming Experience
Beginner
I need to generate a list of 1000 random numbers. and parse them out to a text document on the desktop. and the format must be XXXXXXXX, as in 12345678 or 00000001. Here's what I have so far.

Form1.vb
VB.NET:
Private Sub BtnGenerate_Click

        If Rad1.Checked = True Then
            PictureBox1.Image = ImageList1.Images(0)
            PictureBox1.Visible = True
            Selection = one
        End If

        If Rad1000.Checked = True Then
            PictureBox1.Image = ImageList1.Images(1)
            PictureBox1.Visible = True
            Selection = onethousand
        End If

        If Rad10000.Checked = True Then
            PictureBox1.Image = ImageList1.Images(2)
            PictureBox1.Visible = True
            Selection = tenthousand
        End If



    End Sub


Public variables page
VB.NET:
Public Module PublicVariables

    Public IDlist As ArrayList
    Public Selection As Integer
    Public one As Integer = 1
    Public onethousand As Integer = 1000
    Public tenthousand As Integer = 10000




    Public Sub IDs()
        Dim IDnumber As New Random

        Selection = IDnumber.Next(1, 99999999)

    End Sub

End Module
 
'
VB.NET:
1000 8 digit numbers plus \r\n for each
Dim sb as New StringBuilder(1000 * (8+2))
Dim rng as New Random()
 
For i as Integer = 0 to 999
  sb.AppendLine(rng.Next(0,1000).ToString("00000000"))
Next i
 
Dim sw as New StreamWriter(IO.File.OpenWrite("C:\temp\blah.txt"))
sw.Write(sb.ToString())
 
stringbuilder and stringwriter aren't valid types. I was pretty sure i had used them before though.

VB.NET:
 Dim sb As New Stringbuilder(1000 * (8 + 2))
    Dim rng As New Random


    Private Sub BtnGenerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnGenerate.Click

        If Rad1.Checked = True Then
            PictureBox1.Image = ImageList1.Images(0)
            PictureBox1.Visible = True
            For i As Integer = 0 To 999
                sb.AppendLine(rng.Next(0, 1).ToString("00000000"))
            Next i
        End If

        If Rad1000.Checked = True Then
            PictureBox1.Image = ImageList1.Images(1)
            PictureBox1.Visible = True
            For i As Integer = 0 To 999
                sb.AppendLine(rng.Next(0, 1000).ToString("00000000"))
            Next i
        End If

        If Rad10000.Checked = True Then
            PictureBox1.Image = ImageList1.Images(2)
            PictureBox1.Visible = True
            For i As Integer = 0 To 999
                sb.AppendLine(rng.Next(0, 10000).ToString("00000000"))
            Next i
        End If



    End Sub

    Private Sub BtnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSave.Click
        Dim sw As New StreamWriter(IO.File.OpenWrite("C:\Documents and Settings\Administrator\Desktop\friends.txt"))
        sw.Write(sb.ToString())
    End Sub
 
Last edited:
Public NotInheritable Class StringBuilder
Inherits
System.Object
Member of: System.Text
Summary:
Represents a mutable string of characters. This class cannot be inherited.


Public Class StreamWriter
Inherits
System.IO.TextWriter
Member of: System.IO
Summary:
Implements a System.IO.TextWriter for writing characters to a stream in a particular encoding.


ensure you have made the porper Imports directives
 
Back
Top