hp 28s, hp48 sx, hp 48gx



#10

I look for programs that generate (randomly) n natural numbers without repetitions with n greater or equal to 1 and smaller or equal to N (N being a positive integer.)
Thank you for your help.


#11

Hi, elgar;

All the calculators you mentioned already have a built-in pseudo Random Number generator that uses a seed you can type in. The command to generate a pseudo Random number (to level 1) is [RAND] and the command to "collect" a seed (a real number in Level 1) is [RDZ] (randomize).

Using RPL

You can type in the following program:

« -> N
« RAND N * IP
»
»

You can store it with a private name (e.g.: 'MYRAND' [STO]). Also, maybe you probably know about this, but there is no harm mentioning: the [->] symbol refers to the single right-arrow, not a composition of a minus with a greater-than sign. Just for the records and for my own sake...

IP returns the integer part (truncates, no rounding) of the resulting value from RAND (pseudo Random number) times N (your "range"). In this case, N must be in Level 1 prior to execute the program. If you want the program to use an specific N everytime you run it, use only this part:

« RAND N * IP
»

You should store a value in N prior to execute it. Anytime you need to change the range, you simply type the new value for N and press 'N' [STO]. Also, for changing the pseudo sequence, you just type in a real number and execute [RDZ].

Hope this helps.

Luzi (Brazil)


Edited: 1 May 2004, 1:33 p.m.


#12

Thank you for your swift help;
I look for a program (or programs) that prompts for N and n (n<N) and produces an array (of size n) of randomly chosen integers (all larger or equal to 1 and smaller or equal to N) with no repetitions.


#13

Hello, Elgar;

I'm sorry I didn't answer your question, and I realized that I didn't only after reading Veli-Pekka's answer (thank you, Velli-Pekka). I was worried about generating a random sequence instead of taking care for repetition, and I also confused the range with the quantity of numbers needed.

Veli-Pekka actually answered your question. Anyway, if you need help creating the program that does it, let us know.

Thank you and sorry.

Cheers.

Luiz


Edited: 2 May 2004, 1:51 a.m.

#14

That sounds good.

BUT

If you need to exthaust the 1..N until there are no numbers left, then you could use a list pre-filled with numbers from 1..N

Then you pick one number at time, first 1..N range, remove it , then pick another randomly in the range 1..(N-1), and so on, until the list is empty.

You may gather the results into another list (or vector)

[VPN]


#15

Thank you both for your kind help.
I should have specified that n=[k.N], k being a real fraction< or=1/2.
I look for a aprogram (or programs) the input of which (variables) are n and N and the outcome (result) is an array (of size n) of randomly generated integers all in the range 1,...,N with no repetitions.


#16

I will give you an example of a code, which is how I first understood the problem.

I hope you have the ability to modify it to your needs.

First:

<< RAND * CEIL >> 'NRAND' STO

Then:

<< -> n

<< n 1. { } -> l

<< DUP2 SWAP

FOR k k

NEXT n ->LIST UNROT

FOR r r NRAND DUP2 DUP2 1

- 1 SWAP SUB UNROT 1 + OVER SIZE

SUB + UNROT GET 'l' SWAP STO+

-1.

STEP DROP l AXL

>> >> >> 'LRAN' STO

'LRAN' RCL BYTES => # 830Dh 166.5

Note:

I wrote this in the wee-wee hours.

It works (for all 1..N) but is not optimized.



You could also use the randomizer to pick up an item to be "sorted" as the first element of a list, then the second, etc.

[VPN]


#17

Thank you very much indeed for your kindness and patience.
I have not yet coded it in, I hope it will work.


#18

Be aware! This "solution" simply picks randomly all numbers between 1..N

[VPN]


Possibly Related Threads…
Thread Author Replies Views Last Post
  HP-48GX & 50G Question Matt Agajanian 2 1,842 12-08-2013, 10:17 PM
Last Post: Matt Agajanian
  HP Prime... NOT meant to replace HP48,49,50 ? Chris Pem10 21 5,549 11-18-2013, 03:30 PM
Last Post: Chris Smith
  BATTERIES' SWAP ON HP 48GX aurelio 7 2,548 10-06-2013, 07:50 PM
Last Post: aurelio
  Missing LCD segments (48 SX) Matti Övermark 2 1,348 09-18-2013, 03:50 PM
Last Post: Matti Övermark
  Riemann's Zeta Function update (HP-28S, HP-48G/GX/G+, HP-49G/G+/50g) Gerson W. Barbosa 0 1,057 06-30-2013, 01:01 AM
Last Post: Gerson W. Barbosa
  SpeedBrowser / EQLib Browser for the HP 48S/SX Raymond Del Tondo 0 993 04-21-2013, 11:09 AM
Last Post: Raymond Del Tondo
  Riemann's Zeta Function (HP-28S) Gerson W. Barbosa 8 2,557 02-03-2013, 03:23 PM
Last Post: Gerson W. Barbosa
  HP 48GX with Black LCD - S/N ID Jeff Kearns 4 1,766 12-15-2012, 03:55 PM
Last Post: aurelio
  Error Message/Procedure HP-48SX with TDS Survey SX card bporter101 6 1,974 12-10-2012, 10:18 AM
Last Post: bporter101
  Archive an HP 50G and Restore on an HP 48GX Rudy P. 5 1,989 11-16-2012, 09:24 PM
Last Post: Michael Lopez

Forum Jump: