+ Reply to Thread
Results 1 to 5 of 5

Generating random array with conditions

  1. #1
    Registered User
    Join Date
    03-03-2019
    Location
    Hong Kong
    MS-Off Ver
    Office 365
    Posts
    17

    Generating random array with conditions

    Hi guys,

    Perhaps a peculiar task. My goal is to generate a dynamic array with random percentage weights. Couple of rules on that.

    1. Generate 30 weights.
    2. Each weight must be less than 10%
    3. Sum of all weights must be 100%
    4. For weights that are above 5%, sum of them must be not greater than 40%.

    My thoughts were I could use random array function with max in there, but I don't know how to incorporate sum up to 100, and the 4th rule..

    Example List attached. Any help will be greatly appreciated!!

    Thank you!
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    03-03-2019
    Location
    Hong Kong
    MS-Off Ver
    Office 365
    Posts
    17

    Re: Generating random array with conditions

    Solved it. =LAMBDA(x,LET(y,x,IF(SUM(IF(y>5%,y,0))<40%,y,custy(crit13))))(crit13)

    Custy = =LAMBDA(x,LET(y,x,IF(SUM(IF(y>5%,y,0))<40%,y,custy(crit13))))
    Crit13 = =LET(x,RANDARRAY(30,,,10%,0),x/SUM(x))

  3. #3
    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,351

    Re: Generating random array with conditions

    Thank you for letting us know.
    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.

  4. #4
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: Generating random array with conditions

    Please try non-recursive

    =LET(n,30,p,5%,l,40%,r,RANDARRAY(n),s,r/SUM(r),c,s>=p,o,MAX(0,SUM(s*c)-l),m,o/(n+SUM(-c)),d,s<p-m,IF(c,s-o/SUM(--c),IF(d,s+o/SUM(--d),s)))
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    03-03-2019
    Location
    Hong Kong
    MS-Off Ver
    Office 365
    Posts
    17

    Re: Generating random array with conditions

    Interesting! Where can I learn more about "--c", haven't seen this syntax before? Thank you!

+ 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. [SOLVED] Random number generator not always generating random numbers
    By Murman01 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-03-2021, 05:29 PM
  2. Random Generating Schedule
    By Alucard2015 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 03-12-2020, 06:27 PM
  3. Generating Random Percentages
    By ctp1223 in forum Excel General
    Replies: 4
    Last Post: 07-13-2017, 02:38 AM
  4. Generating a random name
    By shaibn in forum Excel General
    Replies: 3
    Last Post: 02-09-2016, 10:55 AM
  5. Generating a list of Random numbers of random length...
    By Growl in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-19-2013, 12:10 PM
  6. generating random number & 0s and 1s
    By nynamyna in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-22-2011, 05:01 PM
  7. Generating a Random Number of Random Numbers
    By Garrus in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-10-2010, 09:39 AM

Tags for this Thread

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