[scilab-Users] Random selection

Carrico, Paul paul.carrico at esterline.com
Fri Dec 10 11:33:15 CET 2010


Thanks to Daniele and Mathieu


Please consider the environment before printing this e-mail 


-----Message d'origine-----
De : Daniele Andreucci [mailto:andreucci at dmmm.uniroma1.it] 
Envoyé : vendredi 10 décembre 2010 11:26
À : users at lists.scilab.org
Objet : Re: [scilab-Users] Random selection

Carrico, Paul wrote on 12/10/10 10:27:
> Dear all,
>  
> This is a strange idea (but usefull one) : I've a list a X point and I
> would like to select 3 of them in a random way (of course a point can be
> choose only ounce)  
>  
> I can use the following code 
> round(X*rand(1,3))
>  
> neverthless :
> - I've to loop until the 3 integer are different
> - if X becomes small it's diffucult to have 3 different values
>  
> I'm sure these a simplier way to generate these 3 integers ... can I
> have an advice ?
>  
> Thanks
>  
> Paul
> 
> --------------------------------------------------------------------------------
> 

Dear Paul,

you are looking for a selection from a random permutation (since each
point can be selected once).
For example with

grand(1,"prm",a)

(a=column vector) you can proceed as follows:

-->X=10;

-->a=[1:X]'
 a  =

    1.
    2.
    3.
    4.
    5.
    6.
    7.
    8.
    9.
    10.

-->b=grand(1,"prm",a)
 b  =

    2.
    10.
    1.
    5.
    4.
    9.
    8.
    3.
    7.
    6.

-->myselection=b(1:3)
 myselection  =

    2.
    10.
    1.


Daniele

-- 
[ Daniele Andreucci
[ Dip. di Scienze di Base e Applicate per l'Ingegneria
[ via A. Scarpa 16     00161 Roma, Italy
[ tel.    +39 0649766785
[ fax     +39 064957647
[ e-mail:  andreucci at dmmm.uniroma1.it
[ http://www.dmmm.uniroma1.it/~andreucci/
[ gpg pub key id: D3ADC732

--------------------------------------------------------------------------------


Le présent mail et ses pièces jointes sont confidentiels et destinés à la personne ou aux personnes visée(s) ci-dessus. Si vous avez reçu cet e-mail par erreur, veuillez contacter immédiatement l'expéditeur et effacer le message de votre système. Toute divulgation, copie ou distribution de cet e-mail est strictement interdite.

This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error, please contact the sender and delete the email from your system. If you are not the named addressee you should not disseminate, distribute or copy this email.




More information about the users mailing list