Results 1 to 3 of 3

Thread: Picking a Random Number Only Once

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2011
    Posts
    21

    Picking a Random Number Only Once

    Hello,

    I'm trying to figure out how to make a number be randomly picked but only picked once when a button is clicked. I've got the simple random number code down already but I can't seem to figure out how to have it picked only once.

    This is basic random code that I'm using right now.
    Code:
    Randomize()
    Dim value As Integer = CInt(Int((14 * Rnd()) + 1))
    It picks out a number from 1 to 14 and returns it as an integer in "value", and I'm using to set that to open a specific form but I don't want that specific form to open more than once in a session. So if the number three was already picked out then it could never be returned ever again. I was thinking of making it randomize again if it rolls a number that has already come out but I'm still learning basic code and don't exactly know how I would set out on doing this.

    Can anyone point me in the right direction?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Picking a Random Number Only Once

    Follow the CodeBank link in my signature and check out my threads on Unique Random Selections and Randomising A List.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jan 2011
    Posts
    21

    Re: Picking a Random Number Only Once

    Quote Originally Posted by jmcilhinney View Post
    Follow the CodeBank link in my signature and check out my threads on Unique Random Selections and Randomising A List.
    Perfect! Just what I needed. Thanks a bunch

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