How to create a list of random odd numbers

amvukovic shared this question 2 years ago

I would like to create a list of n random different odd numbers in given interval using GeoGebra scripting (not Java Script) and honestly I have no idea how to do this with pure GGB scripting...

Any idea is more then welcome :-)

You can create a shuffled list of odd numbers between the given min and max and select the first n numbers.Od course you have to take care that n doesn't exceed the possible number of odd different numbers between min and max.

I added a try, using the command: First(Shuffle(Sequence(2n + 1, n, round(min / 2) - 1, round(max / 2) - 1)), n)

chris

Files: list.ggb

1

I've found the solution with several lists: (1) list1 of all numbers in given interval, (2) list2A of all even numbers from list1 and list2B of all odd numbers from list1, (3) lists 3A and 3B that are shuffled lists 2A and 2B and then I take wanted n numbers from these lists...

I wonder if there's neater way to do this... ?

1

You can create a shuffled list of odd numbers between the given min and max and select the first n numbers.Od course you have to take care that n doesn't exceed the possible number of odd different numbers between min and max.

I added a try, using the command: First(Shuffle(Sequence(2n + 1, n, round(min / 2) - 1, round(max / 2) - 1)), n)

chris

Files: list.ggb
1

Thanks ccambre!

I was obviously too tired last night and that's the reason why my brain was fried :wink: ... so I've honestly wrote I had no idea how to do it!

You've connected all three steps of my code ( the only thing that my brain could come up to last night :stuck_out_tongue_winking_eye: ) into one neat line of code!

Once again thanks and have a nice weekend.