random number picker

14 views
Skip to first unread message

Paul Ferris

unread,
Sep 3, 2025, 11:37:58 AMSep 3
to Numbas Users
Is it possible to have Numbas randomly select say 6 number but restricting to just ONE being prime?  I am trying to write a question ask student select the PRIME number from a list.  Thanks.

Ulrich Goertz

unread,
Sep 3, 2025, 5:16:53 PMSep 3
to Numbas Users

In that question, Numbas chooses one random entry from a list of primes, and 5 random entries from a list of non-primes, and presents these 6 numbers in ascending order.

Another approach for this kind of problem could be to choose 6 random numbers and then use "Variable testing" to ensure that the condition that exactly one is a prime is met, but in this particular situation this would be more complicated and compute-intensive.

Best regards, Ulrich

Ben Brawn

unread,
Sep 3, 2025, 5:26:40 PMSep 3
to numbas...@googlegroups.com
I would take a list of primes off the internet and a separate list of composite numbers. And make variables like this using those lists. 
 
Prime = random([2,3,5,7…])
Composites = shuffle([4,6,8,…])[0..5]
Options = shuffle([prime]+composites)

Then mark correct if their answer is equal to the variable Prime. 

Let me know if something doesn’t make sense


On Thu, 4 Sep 2025 at 1:38 am, Paul Ferris <paul.fe...@gmail.com> wrote:
Is it possible to have Numbas randomly select say 6 number but restricting to just ONE being prime?  I am trying to write a question ask student select the PRIME number from a list.  Thanks.

--
You received this message because you are subscribed to the Google Groups "Numbas Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to numbas-users...@googlegroups.com.
To view this discussion, visit https://groups.google.com/d/msgid/numbas-users/af0355ef-9faf-44bb-9fc8-2d86b825c50bn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages