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.
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.
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.
Is Excel 2019
Then please change your profile from 2016 to 2019!
i downgrade to 2016 right now
How very confusing!!!
But could you help me Excel 2016
I can't - someone sho does VBA will. Please be patient.
Hi,
any bounds ?
no bro thanks for help me
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 ...
The bound is 0 to 100.
The numbers cant be duplicates
Not negative
A VBA demonstration for starters :
PHP Code:
Sub Demo1()
Dim V, F%, R%
V = [ROW(1:100)-1]
For F = 1 To 99
R = Application.RandBetween(F, 100)
W = V(F, 1)
V(F, 1) = V(R, 1)
V(R, 1) = W
Next
Stop
End Sub
► Do you like it ? ► ► So thanks to click on bottom left star icon « ★ Add Reputation » ! ◄ ◄
Can you put to show all the array before mix and after mix. Thanks for all the help
Cross-posted: https://forum.ozgrid.com/forum/index...help-with-vba/
Remember what the dormouse said
Feed your head
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?
Originally Posted by shg
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/ )
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks