Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15

Thread: generate 4 - digits pin of same characters or digits
Thanks Thanks: 0 Likes Likes: 0

  1. #11
    Board Regular kelly mort's Avatar
    Join Date
    Apr 2017
    Location
    Suhum, Ghana, West Africa
    Posts
    1,518
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Default Re: generate 4 - digits pin of same characters or digits

    Quote Originally Posted by shknbk2 View Post
    How about something like this?

    Code:
    Function ReturnPin() As String
        Dim i As Integer, i2 As Integer
        Randomize
        i = Rnd * 10
        i2 = Rnd * 9
        Select Case i
            Case 10
                i = Rnd * 6
                ReturnPin = i & i + 1 & i + 2 & i + 3
            Case Else
                ReturnPin = i & i & i2 & i2
        End Select
    End Function
    Hahaha

    It would have taken me millennia to figure this logic out!!

    Working very great

    Now all questions exhausted.

    Have a great time
    There Is Always A Better Way

  2. #12
    MrExcel MVP Rick Rothstein's Avatar
    Join Date
    Apr 2011
    Location
    New Jersey, USA
    Posts
    35,251
    Post Thanks / Like
    Mentioned
    92 Post(s)
    Tagged
    33 Thread(s)

    Default Re: generate 4 - digits pin of same characters or digits

    You might be interested in this alternative construction for shknbk2's function (Message #10 )...
    Code:
    Function ReturnPin() As String
      Dim i As Integer, i2 As Integer
      i = [RANDBETWEEN(0,10)]
      If i < 10 Then i2 = Evaluate("MID(""0123456789"",RANDBETWEEN(1,9),1)")
      ReturnPin = Evaluate("IF(" & i & "<10,TEXT(" & i & i & i2 & i2 & ",""0000""),MID(""0123456789"",RANDBETWEEN(1,6),4))")
    End Function
    In another thread where you were testing the PIN's, you indicated that all four digits being the same was an invalid PIN. If you need this function to not return such numbers, then use this version of my function instead...
    Code:
    Function ReturnPin() As String
      Dim i As Integer, i2 As Integer
      i = [RANDBETWEEN(0,10)]
      If i < 10 Then i2 = Evaluate("MID(SUBSTITUTE(""0123456789""," & i & ",""""),RANDBETWEEN(1,9),1)")
      ReturnPin = Evaluate("IF(" & i & "<10,TEXT(" & i & i & i2 & i2 & ",""0000""),MID(""0123456789"",RANDBETWEEN(1,6),4))")
    End Function
    Rick's "mini" blog... http://www.excelfox.com/forum/f22/
    .
    Want to post a small screen shot? See Part B here.

  3. #13
    Board Regular kelly mort's Avatar
    Join Date
    Apr 2017
    Location
    Suhum, Ghana, West Africa
    Posts
    1,518
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Default Re: generate 4 - digits pin of same characters or digits

    Okay cool. For now I am interested in the first part of the code you provided. I will later see what I can do with the second part. For now I need those same numbers in place

    It's seems to randomly select the various numbers cooler. Almost even for the "abcd", "aaaa", "aabb" formats.

    Shknbk's version favoured the "aabb" than the others

    PS.
    Did you intentionally leave out the

    Randomize key word?
    Last edited by kelly mort; Aug 25th, 2019 at 04:35 AM.
    There Is Always A Better Way

  4. #14
    MrExcel MVP Rick Rothstein's Avatar
    Join Date
    Apr 2011
    Location
    New Jersey, USA
    Posts
    35,251
    Post Thanks / Like
    Mentioned
    92 Post(s)
    Tagged
    33 Thread(s)

    Default Re: generate 4 - digits pin of same characters or digits

    Quote Originally Posted by kelly mort View Post
    PS.
    Did you intentionally leave out the

    Randomize key word?
    Yes... you only need the Randomize statement when you use VB's Rnd function... I used Excel's RANDBETWEEN function instead which does not require the Randomize statement.
    Rick's "mini" blog... http://www.excelfox.com/forum/f22/
    .
    Want to post a small screen shot? See Part B here.

  5. #15
    Board Regular kelly mort's Avatar
    Join Date
    Apr 2017
    Location
    Suhum, Ghana, West Africa
    Posts
    1,518
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Default Re: generate 4 - digits pin of same characters or digits

    Okay
    There Is Always A Better Way

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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