I am working on an experiment in which I want to generate 100 random
numbers between 1 - 100, but a number should not be repeated. Say if 1
is generated then it should not be generated again. Basically I want
all 100 numbers between 1 and 100 without any repetetion and that too
in a random manner.
Right now I am using the script
Dim i as Integer
Dim Rand as Integer
For i = 1 to 100
Rand = Random(1,100)
Debug.Print "Random number is = " & Rand
Next i
This is giving me random numbers between 1 and 100, but the numbers
are repeated.
Please let me know if there is any logic of generating random numbers
without any repeat.
Any help is really appreciated.
Regards
Shivani
Simply put, you want to draw the numbers 1-100 in a shuffled order.
Easiest to do this making a List with the numbers 1-100, setting the
List to Random, then drawing samples from the List, perhaps as a
nested List. Please work through the appropriate tutorials in the
manuals that came with E-Prime, with particular attention to Appendix
C of the User's Guide. But if you would really rather roll your own
than use a List, then you want to program a Fisher-Yates shuffle
algorithm, just look that up on Wikipedia.
-- David McFarlane, Professional Faultfinder
Dim i as Integer
Dim Rand100(1 to 100) as Integer
For i = 1 to 100
Rand100(i) = i 'fills array
Next i
RandomizeArray Rand100 'randomises
For i = 1 to 100
Debug.Print "Random number is = " & Rand100(i) 'show output
Next i
Michiel Spapé
Research Fellow
Perception & Action group
University of Nottingham
School of Psychology
Hi,
Rand = Random(1,100)
Next i
Regards
Shivani
--
You received this message because you are subscribed to the Google Groups "E-Prime" group.
To post to this group, send email to e-p...@googlegroups.com.
To unsubscribe from this group, send email to e-prime+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/e-prime?hl=en.
This message has been checked for viruses but the contents of an attachment
may still contain software viruses which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.
Thanks David and Michiel for all your help and time. I am trying out
this logic in the experiment.
Thanks again.
Regards
Shivani
On Apr 9, 5:32 am, Michiel Spape <Michiel.Sp...@nottingham.ac.uk>
wrote:
> For more options, visit this group athttp://groups.google.com/group/e-prime?hl=en.
>
> This message has been checked for viruses but the contents of an attachment
> may still contain software viruses which could damage your computer system:
> you are advised to perform your own checks. Email communications with the
> University of Nottingham may be monitored as permitted by UK legislation.- Hide quoted text -
>
> - Show quoted text -