cancel
Showing results for 
Search instead for 
Did you mean: 
REYNEL
Level 3
38 34 1 3
Message 1 of 33
1,368
Flag Post

Solved!

Generation of a list of random numbers with specified limits

HP Recommended
HP 50g
Microsoft Windows 7 (32-bit)

Is it possible in the HP 50g to generate a list of random numbers, for example a list of 10 randoms numbers between 50.20 and 104.35?

thank you

Reynel

0 Kudos
32 REPLIES 32
Joe_Horn
Level 8
622 609 117 207
Message 2 of 33
Flag Post
HP Recommended

@REYNEL wrote:

Is it possible in the HP 50g to generate a list of random numbers, for example a list of 10 randoms numbers between 50.20 and 104.35?

thank you

Reynel


 One way is by writing a little program like this:

 

<<  1  10  START  RAND  54.15  *  50.2  +  NEXT  10  ->LIST  >>

 

Please note that the "->" above stands for the single right-arrow character.

 

Disclaimer: I don't work for HP. I'm just another happy HP calculator user.

-Joe-
Maké
Level 9
3,551 3,490 180 541
Message 3 of 33
Flag Post
HP Recommended

Hi!, @REYNEL:

 

Welcome, in this new year HP Forum !. :generic:

 

You too, can use ...

L2.  Randomize a List ‘RANL’ : In page 8 of 26 of One Minute Marvels, from ... http://www.hpcalc.org/details/1691

16 commands,  62.5 Bytes,  #1F8Ch.   Timing: 100 elements  in 1.52_sec.

 

<<   LIST→   →   t   <<  1   t   FOR   n   n   RAND  *  CEIL   ROLLD  NEXT   t   →LIST   >>    >>

 

 

 

Kind Regards !.
Have a nice day !.
@Maké (Technical Advisor Premium - HP Program Top Contributor).
Provost in HP Spanish Public Forum ... https://h30467.www3.hp.com/
0 Kudos
REYNEL
Author
Level 3
38 34 1 3
Message 4 of 33
Flag Post
HP Recommended

Make, many many thank you!

0 Kudos
REYNEL
Author
Level 3
38 34 1 3
Message 5 of 33
Flag Post
HP Recommended

Joe_Horn,

Thank you very much! This approach worked very well.

0 Kudos
Maké
Level 9
3,551 3,490 180 541
Message 6 of 33
Flag Post
HP Recommended

Hi!, @REYNEL:

 

Is very important what you know how work RANDOM, in HP 50G.

 

Random numbers :

The calculator provides a random number generator that returns a uniformly distributed random real number between 0 and 1. To generate a random number, use function RAND from the MTH/PROBABILITY sub-menu.
Kind Regards !.
Have a nice day !.
@Maké (Technical Advisor Premium - HP Program Top Contributor).
Provost in HP Spanish Public Forum ... https://h30467.www3.hp.com/
0 Kudos
Joe_Horn
Level 8
622 609 117 207
Message 7 of 33
Flag Post
HP Recommended

@Maké wrote:

 

You too, can use ...

L2.  Randomize a List ‘RANL’ : In page 8 of 26 of One Minute Marvels, from ... http://www.hpcalc.org/details/1691

16 commands,  62.5 Bytes,  #1F8Ch.   Timing: 100 elements  in 1.52_sec.

 

<<   LIST→   →   t   <<  1   t   FOR   n   n   RAND  *  CEIL   ROLLD  NEXT   t   →LIST   >>    >>

 


Please note that the above program only shuffles an already-existing list.  That is not what the original poster requested.  However, I'm glad that Maké mentioned it, because studying the logic in this program (and all the programs in One Minute Marvels) is highly instructive, and can also be intellectually stimulating and entertaining.

-Joe-
0 Kudos
Maké
Level 9
3,551 3,490 180 541
Message 8 of 33
Flag Post
HP Recommended

Hi!, @Joe:

 

If you are Engineer or Professor, then you must be know what needed, in each case, analyze and indicate the theory or syntax and this is more important what the example, for the user. 

Kind Regards !.
Have a nice day !.
@Maké (Technical Advisor Premium - HP Program Top Contributor).
Provost in HP Spanish Public Forum ... https://h30467.www3.hp.com/
0 Kudos
REYNEL
Author
Level 3
38 34 1 3
Message 9 of 33
Flag Post
HP Recommended

Joe, your program worked like a charm. Thank you very much again!

However,  the other answer that I got was confusing to me and I did not get the expected result. This time, I would like to apply the same problem as stated before, but instead of a list of 10 random numbers with the specified limits,  I would like to to build a matrix with 3 columns and 10 rows filled with randoms numbers in the bound limits. That is between 50.20 and 104.35.

I was able to build this matrix by running your program 3 times and storing each run with a different variable and finally using the augmented matrix command to convert the 10 X 1 list into a 10X3 matrix. This is a painful task, since I have to repeated many times for a statistical project. Is it possible modify  your original program and adapt it for a 10 by 3 matrix?

Thank you!

 

Reynel

0 Kudos
Joe_Horn
Level 8
622 609 117 207
Message 10 of 33
Flag Post
HP Recommended

@REYNEL wrote:

Joe, your program worked like a charm. Thank you very much again!

However,  the other answer that I got was confusing to me and I did not get the expected result. This time, I would like to apply the same problem as stated before, but instead of a list of 10 random numbers with the specified limits,  I would like to to build a matrix with 3 columns and 10 rows filled with randoms numbers in the bound limits. That is between 50.20 and 104.35.

I was able to build this matrix by running your program 3 times and storing each run with a different variable and finally using the augmented matrix command to convert the 10 X 1 list into a 10X3 matrix. This is a painful task, since I have to repeated many times for a statistical project. Is it possible modify  your original program and adapt it for a 10 by 3 matrix?

Thank you!

 

Reynel


The following little program will work, but it uses a slightly different approach than the previous program:

 

<< { 10 3 } 0 CON { 1 1 } DO RAND 54.15 * 50.2 + PUTI UNTIL -64 FS? END DROP >>

 

Change the initial list for other matrix dimensions.  Change the two numbers in the middle of the program to adjust the random range and smallest number respectively.  If you have any questions about how this works, just holler.

-Joe-
† The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation