Post Reply 
Random Integers, No Repeats
08-09-2023, 05:31 PM (This post was last modified: 08-09-2023 05:34 PM by Joe Horn.)
Post: #12
RE: Random Integers, No Repeats
(08-09-2023 05:21 PM)roadrunner Wrote:  srand(integer) initializes the rand() function

Awesome! Thanks!

Here's some more info about the rand(X,Y,Z) function from Bernard's documentation for XCAS:

Bernard Wrote:The rand command can also choose elements without replacement. If you give rand three integer arguments, rand(p,n1,n2) then it will return p distinct random integers from n1 to n2.
If you enter rand(2,1,10) for example, you will get 2 distinct random numbers from 1 to 10; perhaps [2,9].

You can also choose (without replacement) random elements of a given list. For this, you give rand a postive integer n and a list L; rand(n,L) will then return n random elements from the list.
If you enter rand(3,["a","b","c","d","e","f","g","h"]) you might get ["c","b","e"].
The list can have repeated elements; if you enter rand(4,["r","r","r","r","v","v","v"]) you might get ["v","v","r","v"].

<0|ΙΈ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Random Integers, No Repeats - lrdheat - 08-09-2023, 02:30 AM
RE: Random Integers, No Repeats - Joe Horn - 08-09-2023, 04:54 AM
RE: Random Integers, No Repeats - nickapos - 08-09-2023, 04:59 PM
RE: Random Integers, No Repeats - Joe Horn - 08-09-2023, 05:10 PM
RE: Random Integers, No Repeats - lrdheat - 08-09-2023, 01:24 PM
RE: Random Integers, No Repeats - Joe Horn - 08-09-2023 05:31 PM
RE: Random Integers, No Repeats - nickapos - 08-09-2023, 06:04 PM
RE: Random Integers, No Repeats - parisse - 08-09-2023, 06:09 PM



User(s) browsing this thread: