HP Prime Program: Sampling Without Replacement - Printable Version +- HP Forums ( https://archived.hpcalc.org/museumforum)+-- Forum: HP Museum Forums ( https://archived.hpcalc.org/museumforum/forum-1.html)+--- Forum: Old HP Forum Archives ( https://archived.hpcalc.org/museumforum/forum-2.html)+--- Thread: HP Prime Program: Sampling Without Replacement ( /thread-252011.html) |

HP Prime Program: Sampling Without Replacement - Eddie W. Shore - 10-02-2013
SAMPLE - Generate a list of random integers from 1 to N using sample without replacement. Re: HP Prime Program: Sampling Without Replacement - Joe Horn - 10-02-2013
If instead of a list, an
E.g. rand(6,1,6) --> [4,1,2,6,5,3] (order varies, of course). The syntax is rand(how many integers you want, lowest integer, greatest integer). If "how many" is greater than greatest-lowest+1, it correctly errors. It's very fast; on the physical calculator it generates a shuffled array of all the integers between 1 and 1000 in 0.126 seconds. The emulator does 10000 in 0.5 seconds on my laptop.
-Joe-
Re: HP Prime Program: Sampling Without Replacement - Helge Gabert - 10-02-2013
Good to know. It would make sense to add "rand" to the catalog.
Is there something similar to AXL (array to list and vice versa) built into the Prime? Thanks!
Re: HP Prime Program: Sampling Without Replacement - Peter Murphy (Livermore) - 10-02-2013
Joe, it might be of interest to know timings on other tasks, including benchmark tasks. Is there already a list of such things? Have I missed it? Thanks.
Re: HP Prime Program: Sampling Without Replacement - Richard Berler - 10-02-2013
Nice to know about rand(). Is there a way to know about commands that are not in the catalog? Is it possible to sort the numbers from this sort of output []'s as opposed to {}'s? Can one concatenate when dealing with []'s? If so, rand() would shorten my lotto programs which are fairly short...I used sort, delta list, product list to determine if I had repeated numbers...rand() shortens that up, but doesn't seem to lend itself to sorting so that I can have a nice output of increasing numbers, nor does it seem to offer the chance of concatenation where I can have my 5 lotto numbers with the bonus ball labeled and appended to the numbers.
I'm not lotto crazy, but it was a nice introduction to the programming and syntax...
Re: HP Prime Program: Sampling Without Replacement - Richard Berler - 10-03-2013
What's also odd is that in CAS, SORT(rand(5,1,56)),rand(1,1,46); yields a nice result, yet it produces a bad argument error in program mode. Actually, a syntax error as stated...bad argument if I had in program, SORT(rand(5,1,56)) and rand(1,1,46); .
Re: HP Prime Program: Sampling Without Replacement - Joe Horn - 10-03-2013
Quote:Simple answer: If such a list exists, I hope somebody posts it. Meta-answer: It would be very easy to create that list, because the built-in time() function returns the execution time of any expression; that's how I timed the rand() examples above: time(rand(10000,1,10000)) --> 0.223 (seconds, on my tower computer)
Note: In CAS, time() must be spelled in lowercase.
Re: HP Prime Program: Sampling Without Replacement - Joe Horn - 10-03-2013
Quote:Most of them can be found in the Xcas documentation, but be forewarned: Xcas has roughly twice as many commands as Prime. One way to "cheat" and find out if Prime recognizes a command is to type it in CAS without any arguments. If it is returned as-is, then it is NOT recognized. If it is returned in single quotation marks, or if it does something(!), then it IS recognized.
Examples:
Quote:Yes. SORT() works on arrays just as well as lists: sort(rand(6,20,25)) --> [20,21,22,23,24,25] (silly example)
Quote:concat([2,3,4],[7,8,9]) --> [2,3,4,7,8,9] Hope that helps!
-Joe-
Re: HP Prime Program: Sampling Without Replacement - parisse - 10-03-2013
If you are interested in timings, there is a shortcut I used and that was not removed: enter your command then tap Sto then press ,
About random number, Xcas has now relatively efficient generators for a selection of probability law, some of them should also work on Prime, for example
Re: HP Prime Program: Sampling Without Replacement - Helge Gabert - 10-03-2013
What is the current XCAS documentation? Is it this http://www-fourier.ujf-grenoble.fr/~parisse/giac/cascmd_en.pdf or is there something else you recommend?
Thanks!
Re: HP Prime Program: Sampling Without Replacement - Han - 10-03-2013
Quote:
It seems to me the "power" behind the HP Prime is partly locked away in CAS environment. I think a lot of folks are anxiously awaiting for the moment when creating CAS programs will be as easy as creating non-CAS ones. Is this something that would take a while to implement, though?
Re: HP Prime Program: Sampling Without Replacement - parisse - 10-03-2013
Quote:This is the best documentation that we have in English. If you can read French, the French documentation is much more complete (and if you read Greek, there is also a translation in Greek). I would be glad to find people writing doc for Xcas/Prime CAS in English by the way:-) Re: HP Prime Program: Sampling Without Replacement - Helge Gabert - 10-03-2013
Merci de me rĂ©pondre!
Re: HP Prime Program: Sampling Without Replacement - Joe Horn - 10-04-2013
Quote:STORE COMMA to launch a timer... but of course! The hidden timer in the HP-45 was also launched via an undocumented key combination! But in that case it was RCL CHS+7+8. Thanks, Bernard! |