+ Reply to Thread
Results 1 to 7 of 7

Random numbers generator

  1. #1
    Registered User
    Join Date
    12-06-2016
    Location
    Poole
    MS-Off Ver
    MS 365 Subscription, Vers. 2310
    Posts
    84

    Random numbers generator

    Hello all

    I have been using the function below to generate x amount of random no. between two no I input (e.g. I need random and unique no between 10 and 50). The function works great, the only problem is that when I use it again to generate a new set of no. it changes the initial ones.

    I would like it to generate new no. every time i use it but keep the initial ones (if that makes sens).


    'Function RandLotto(Bottom As Integer, Top As Integer, _

    Amount As Integer) As String

    Dim iArr As Variant

    Dim i As Integer

    Dim r As Integer

    Dim temp As Integer



    Application.Volatile



    ReDim iArr(Bottom To Top)

    For i = Bottom To Top

    iArr(i) = i

    Next i



    For i = Top To Bottom + 1 Step -1

    r = Int(Rnd() * (i - Bottom + 1)) + Bottom

    temp = iArr(r)

    iArr(r) = iArr(i)

    iArr(i) = temp

    Next i



    For i = Bottom To Bottom + Amount - 1

    RandLotto = RandLotto & " " & iArr(i)

    Next i



    RandLotto = Trim(RandLotto)



    End Function'

    Thanks

  2. #2
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Random numbers generator

    Can you post a sample file with the desired output?
    Where you need to keep the last or previous results?
    As for the new results, you need them to be unique and different from the initial results and what about the number of random numbers needed each time?
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  3. #3
    Registered User
    Join Date
    12-06-2016
    Location
    Poole
    MS-Off Ver
    MS 365 Subscription, Vers. 2310
    Posts
    84

    Re: Random numbers generator

    I have attached an example sheet

    It does not really matter where the results are stored. After using the function once (e.g I need 7 random no from 1 to 50) the results appear in the cell where i used the RandLotto funct.

    When I use it a second time (e.g I want 11 random no. from 23 to 60) the results do not need to be different from the first ones.

    Thank for your time
    Attached Files Attached Files

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Random numbers generator

    Try change to
    Please Login or Register  to view this content.

  5. #5
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Random numbers generator

    Have a look at this file
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    12-06-2016
    Location
    Poole
    MS-Off Ver
    MS 365 Subscription, Vers. 2310
    Posts
    84

    Re: Random numbers generator

    Thank you both for all the help. The sample attached Is exactly what I need.

    Cheers

  7. #7
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Random numbers generator

    You're welcome. Glad we can offer some help for you
    Please mark the thread as solved

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [VBA] Create a random unique numbers generator without functions
    By alexgoaga in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-27-2017, 07:33 AM
  2. Replies: 5
    Last Post: 06-21-2013, 10:40 AM
  3. Random number generator, discluding specific numbers
    By JVesuvius in forum Excel General
    Replies: 2
    Last Post: 01-02-2013, 12:43 PM
  4. Need Random Number Generator but with Weighted Probability for Certain Numbers...
    By michaeljoeyeager in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 07-13-2012, 03:52 PM
  5. Need Help with a Random Number Generator with Weighted Probability for Certain Numbers
    By michaeljoeyeager in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-13-2012, 02:48 PM
  6. Random numbers generator
    By Eric Excels in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-14-2011, 08:49 AM
  7. Random number generator and matching all numbers
    By Zyphon in forum Excel General
    Replies: 2
    Last Post: 03-14-2008, 04:40 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1