+ Reply to Thread
Results 1 to 18 of 18

generate 100 random numbers of which 50 should be even numbers and 50 odd numbers

  1. #1
    Registered User
    Join Date
    10-26-2022
    Location
    spain
    MS-Off Ver
    2016
    Posts
    7

    generate 100 random numbers of which 50 should be even numbers and 50 odd numbers

    Hi I need to generate 100 random numbers of which 50 should be even numbers and 50 odd numbers, they should be stored in an array as follows 0 to 49 even numbers, 50 to 99 odd numbers.

    Then I need to mix the order of the array.
    Can someone help me.
    Last edited by AliGW; 10-26-2022 at 05:42 AM. Reason: Thread title improved - please make your thread titles explicit & not generic in future.

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,830

    Re: generate 100 random numbers of which 50 should be even numbers and 50 odd numbers

    Administrative Note:

    Welcome to the forum.

    Is you forum profile showing the version of Excel that you need this to work for? There is no version 23 ...

    Members will tailor the solutions they offer to the version of Office (Excel, NOT Windows) that you have. Please check that your forum profile is up-to-date in this respect. If you aren't sure, in Excel go to File | Account and report what it says below the MS logo at the top of that page. If your version is for Mac, please also state this.

    The three most recent versions of Excel are Excel 2019, Excel 2021 and MS365 - if you are using MS365, please give this name along with the release number in your profile (e.g. MS365 Version 2211). This is in the About Excel section further down the Account page.

    Thanks.

    Administrative Note:

    Although we value your privacy as much you do, it could be important that members have a rough idea of your location as the solutions they offer may be affected by your locale. For instance, you might in the future post questions which are related to your regional settings.

    With this in mind, please update your profile to something more precise (something such as UK, Europe, USA, UAE, etc. will suffice).

    Thank you for helping us to help you.

    Administrative Note:

    We would very much like to help you with your query, however the thread title does not really convey what your request is about. Tell us what you are trying to do, not how you think it should be done.

    Please take a moment to amend your thread title. Make sure that the title properly explains your request. Your title should be explicit and not be generic (this includes function names used without an indication of what you are trying to achieve).

    Please see Forum Rule #1 about proper thread titles and adjust accordingly. To edit the thread title, open the original post to edit and then click on Go Advanced (bottom right) to access the area where you can edit your title.

    (Note: this change is not optional. As you are new here, I have done it for you this time.)
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Registered User
    Join Date
    10-26-2022
    Location
    spain
    MS-Off Ver
    2016
    Posts
    7

    Re: generate 100 random numbers of which 50 should be even numbers and 50 odd numbers

    Is Excel 2019

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,830

    Re: generate 100 random numbers of which 50 should be even numbers and 50 odd numbers

    Then please change your profile from 2016 to 2019!

  5. #5
    Registered User
    Join Date
    10-26-2022
    Location
    spain
    MS-Off Ver
    2016
    Posts
    7

    Re: generate 100 random numbers of which 50 should be even numbers and 50 odd numbers

    i downgrade to 2016 right now

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,830

    Re: generate 100 random numbers of which 50 should be even numbers and 50 odd numbers

    How very confusing!!!

  7. #7
    Registered User
    Join Date
    10-26-2022
    Location
    spain
    MS-Off Ver
    2016
    Posts
    7

    Re: generate 100 random numbers of which 50 should be even numbers and 50 odd numbers

    But could you help me Excel 2016

  8. #8
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,830

    Re: generate 100 random numbers of which 50 should be even numbers and 50 odd numbers

    I can't - someone sho does VBA will. Please be patient.

  9. #9
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: generate 100 random numbers of which 50 should be even numbers and 50 odd numbers


    Hi,

    any bounds ?

  10. #10
    Registered User
    Join Date
    10-26-2022
    Location
    spain
    MS-Off Ver
    2016
    Posts
    7

    Re: generate 100 random numbers of which 50 should be even numbers and 50 odd numbers

    no bro thanks for help me

  11. #11
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: generate 100 random numbers of which 50 should be even numbers and 50 odd numbers


    As to generate any number lower & upper bounds are necessary !
    And you forgot to explain if numbers can be negative and if the array can contain duplicates ...

  12. #12
    Registered User
    Join Date
    10-26-2022
    Location
    spain
    MS-Off Ver
    2016
    Posts
    7

    Re: generate 100 random numbers of which 50 should be even numbers and 50 odd numbers

    The bound is 0 to 100.


    The numbers cant be duplicates

    Not negative

  13. #13
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Try this ...


    A VBA demonstration for starters :

    PHP Code: 
    Sub Demo1()
        
    Dim VF%, R%
            
    = [ROW(1:100)-1]
        For 
    1 To 99
            R 
    Application.RandBetween(F100)
            
    V(F1)
            
    V(F1) = V(R1)
            
    V(R1) = W
        Next
            Stop
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !

  14. #14
    Registered User
    Join Date
    10-26-2022
    Location
    spain
    MS-Off Ver
    2016
    Posts
    7

    Re: generate 100 random numbers of which 50 should be even numbers and 50 odd numbers

    Can you put to show all the array before mix and after mix. Thanks for all the help

  15. #15
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: generate 100 random numbers of which 50 should be even numbers and 50 odd numbers

    Rory

  16. #16
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: generate 100 random numbers of which 50 should be even numbers and 50 odd numbers

    What role does VBA play in this question, because I would do this without VBA.

    You haven't given a range for you numbers, so I will assume 1 to 1000.

    For even numbers =RANDBETWEEN(1,500)*2
    For odd numbers =RANDBETWEEN(1,500)*2-1
    Then to shuffle the array, add a column of random uniques in the column adjacent to these (I would use the RAND() function, and probably fix the values by doing a copy/paste special/as values), then sort the list in ascending or descending order according to the second column.

    Of course, the same steps can be done in VBA, if desired. If memory serves, VBA does not have a built in RANDBETWEEN() function, so you can either see if this Excel function is available to VBA, or build one from VBA's built in Rnd() function. Remember that VBA will always generate the same sequence of random numbers until you execute a Randomize command to randomize VBA's built in random number generator.

    Does that help?
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  17. #17
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: generate 100 random numbers of which 50 should be even numbers and 50 odd numbers


    Quote Originally Posted by MrShorty View Post
    VBA does not have a built in RANDBETWEEN() function, so you can either see if this Excel function is available to VBA
    Like you can check in my previous VBA SSS demonstration ...
    Last edited by Marc L; 10-26-2022 at 12:07 PM.

  18. #18
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,830

    Re: generate 100 random numbers of which 50 should be even numbers and 50 odd numbers

    Administrative Note:

    We would very much like to help you with your query, however it has been brought to our attention that the same query has been posted on one or more other forums and you have not told us about this. You are required to do so.

    Please see Forum Rule #3 about cross-posting and adjust accordingly. Read this to understand why we (and other sites like us) consider this to be important: https://excelguru.ca/a-message-to-forum-cross-posters/

    (Note: this requirement is not optional. As you are new here, I shall do it for you this time: https://forum.ozgrid.com/forum/index...help-with-vba/ )

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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