Jump to content
Server Maintenance This Week. ×

Recursive CF help please


Kris M

This topic is 4408 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I'm looking to build a recursive cf that generates a non repeating value list of positive integers within the upper limit and the quantity of items in the list specified at run time.

for example the user enters 12 into a global field (ceiling) and 5 into a global field (qty). The cf should return a list of 5 random, non repeating, numbers in the range of 1 thru 12..

1, 2, 4, 7, 12 ....good

1, 1, 2, 6, 9 ... no good because of the repeating 1

0, 6, 8, 9 11 .. no good because of the 0

3, 9, 10, 11, 13 ... no good because of the 13

4, 5, 6, .. no good because their are only 3 numbers

-3, 4, 5, 8, 10... no good because of the -3

you get the picture.

I've been trying to wrap my left brain around this for a while now and cant seem to get it.

TIA

Help me Obi Wan.. your my only hope

Link to comment
Share on other sites

Try:

UniqueSet ( limit ; setSize ) =

Case (

setSize > limit ; "error" ;



Let ( [

item = Int ( Random * limit ) + 1 ;

cache =  List ( item ; Case ( setSize > 1 ; UniqueSet ( limit ; setSize - 1 ) ) )

] ;

Case (

ValueCount ( FilterValues ( cache ; item ) ) > 1 ; UniqueSet ( limit ; setSize ) ;

cache

)

)



)

  • Like 2
Link to comment
Share on other sites

Try:

UniqueSet ( limit ; setSize ) =

When you give everyone the answer, no one learns anything! .. I know it usually just drags out the entire conversation usually huH!.

Happy Tax days!!!

-i

Edited by Lee Smith
Please don't quote the whole post if you aren't making in line comment.
Link to comment
Share on other sites

When you give everyone the answer, no one learns anything! .. I know it usually just drags out the entire conversation usually huH!.

Happy Tax days!!!

-i

Imoree..

In my case I learned alot from the solution... might take me a while but probably could write a recursive CF of my own... so speak for yourself, not for me : )

Link to comment
Share on other sites

This topic is 4408 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.