# Error 502 produced inconsistently with Randbetween/Choose nested function

Mojave 10.14.6, LO 7.0.6.2

I’m using a mixture of the Randbetween/Choose functions in an attempt to generate two numbers in two cells between 1 and 8, the first being generated with RANDBETWEEN(1,8) (although is is currently a validated list with numbers between 1 and 8) and the second being any number except the first e.g. if the first number is 1, the second number can be any number except 1 i.e. numbers 2-8.

I’ve noticed upon testing this formula that certain numbers in the first cell elicit a “error 502” result in the second, but only intermittently; other times when the same numbers appear in the first cell a number, rather than error 502, is generated in the second cell.
Just wondering what this is all about, and how I can avoid an “error 502” generation. I haven’t really used Choose before so any assistance is greatly appreciated.
Thanks.

numbers sometimes triggering error 502.ods

Of course it will give you an Err:502 when your formula

``````=IFS(A2=1;RANDBETWEEN(2;8);A2=2;CHOOSE(RANDBETWEEN(1;8);1;3;4;5;6;7;8);A2=3;CHOOSE(RANDBETWEEN(1;8);1;2;4;5;6;7;8);A2=4;CHOOSE(RANDBETWEEN(1;8);1;2;3;5;6;7;8);A2=5;CHOOSE(RANDBETWEEN(1;8);1;2;3;4;6;7;8);A2=6;CHOOSE(RANDBETWEEN(1;8);1;2;3;4;5;7;8);A2=7;CHOOSE(RANDBETWEEN(1;8);1;2;3;4;5;6;8);A2=8;RANDBETWEEN(1;7))
``````

gets e.g. `2` in `A2`, and tries to calculate the sub-formula

``````CHOOSE(RANDBETWEEN(1;8);1;3;4;5;6;7;8)
``````

and `RANDBETWEEN` happens to return 8 - so `CHOOSE` tries to find the 8th value in the list `1;3;4;5;6;7;8` having only 7 elements.

By the way, all that formula could be replaced by

``=RANDBETWEEN(1;7)+(CURRENT()>=A2)``

Maybe the only really useful application of CURRENT().