Results 1 to 6 of 6

Thread: Random and MethodNext

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2007
    Posts
    3

    Question Random and MethodNext

    I am new to coding and I some advice with coding a math equation (multiplaction)using RandomObject.Next

    This my statements:

    Module MathQuiz
    Sub Main()
    'create random Mathequation
    Dim randomObject As New Random()
    Dim randomNumber As Integer = randomObject.Next() 'generate random number
    Dim j As Integer
    Dim k As Integer

    'generate 20 random numbers between 1 and 15
    For j As Integer = 1 To 15

    Next
    Console.Write()

    For k As Integer = 1 To 15
    Console.Write("randomObject.Next, k = 7")

    If j And k Mod 15 = 0 Then

    Console.WriteLine()
    Console.ReadLine()

    End If
    Next

    End Sub

    End Module 'MathQuiz

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Random and MethodNext

    Thread Moved
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431

    Re: Random and MethodNext

    Quote Originally Posted by electro53
    I am new to coding and I some advice with coding a math equation (multiplaction)using RandomObject.Next ...
    There's no question here... could you be more specific?
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

  4. #4
    Lively Member
    Join Date
    May 2004
    Posts
    72

    Re: Random and MethodNext

    Hi,

    Don't know what you are doing, but for the part you want to generate 20 random numbers between 1 and 15

    try this
    Code:
    For j As Integer = 1 To 20
        Console.Write(randomObject.Next(1,15+1))
        ' Public Overridable Function [Next](ByVal minValue As Integer, ByVal maxValue As Integer) As Integer
        ' returns greater than or equal to minValue and less than maxValue
        ' the range of return values includes MinValue but not MaxValue.
        ' that's why (15+1), NOT 15
    Next

  5. #5
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: Random and MethodNext

    Seems easier to do in VB6. Build a form with a listbox to hold the numbers:
    Code:
    Private Sub Form_Load()
    Randomize
    For I = 1 To 20
        List1.AddItem Str$(Int(Rnd * 15) + 1)
    Next
    End Sub
    Doctor Ed

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Random and MethodNext

    20 random numbers between 1 and 15 would generate some dups.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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