M MDEnt Member Licensed User Longtime User Oct 14, 2011 #1 Is it possible to generate a random integer from a list of numbers or predefined set - that may not be in order. For example - generate a random number from 1,2,4,5 (no 3 allowed). Last edited: Oct 14, 2011
Is it possible to generate a random integer from a list of numbers or predefined set - that may not be in order. For example - generate a random number from 1,2,4,5 (no 3 allowed).
D dlfallen Active Member Licensed User Longtime User Oct 14, 2011 #2 One simple way is to put the numbers into an array, then generate an array index at random. Upvote 0
M MDEnt Member Licensed User Longtime User Oct 14, 2011 #3 Thanks...makes sense, is there specific sytnax to use Rnd in this case? - I'm actually going to use a list from an Array. cardsLST.AddAll(Array As Int(1,2,4,5)) Upvote 0
Thanks...makes sense, is there specific sytnax to use Rnd in this case? - I'm actually going to use a list from an Array. cardsLST.AddAll(Array As Int(1,2,4,5))
klaus Expert Licensed User Longtime User Oct 14, 2011 #4 Try cardsLST.Get(Rnd(0,4)) Instead of giving directly an index this code generates a random integer between 0 and 3 as the index. Best regards. Upvote 0
Try cardsLST.Get(Rnd(0,4)) Instead of giving directly an index this code generates a random integer between 0 and 3 as the index. Best regards.
K kickaha Well-Known Member Licensed User Longtime User Oct 14, 2011 #5 Or better B4X: cardsLST.Get(Rnd(0,cardsLST.Length)) Then the list of numbers can be any size Upvote 0
M MDEnt Member Licensed User Longtime User Oct 14, 2011 #6 Thanks so much - I'm going to play around with both - I'm sure both will come in handy! Upvote 0