The worst one!

  • 12 years ago

    I don't know what to say! Just please see the second page of this thread : http://www.developerfusion.co.uk/forums/t/48285/page/2/

    I'm now in a bad mood!!




    Forum: C#
    Posted: Aug 15, 9:57 AM [GMT 0]
    Post Subject: Re: Random Numbers
    Post author: incidentals

    The last reply is correct ... when random numbers are generated a seed value must be used as random numbers are really just a list of previously randomised numbers for use by the programmer.

    even if you use a different seed value you will not ensure unique random numbers from a set of possible numbers. you will always have to check and see that a number has not been chosen. and if it has re select a number.

    this method may have you thrashing about trying to get the last available number in a set, currently not selected. ie the number 19 has not been selected so far and you already have all the rest, but must keep picking and selecting until it is.

    Try the following:

    (1) create an array that will hold your numbers or object or questions or what ever.

    (2) create a temp structure to hold 1 instance of the number or object or question or what ever.

    (3)fill the array with your numbers or objects or questions or what ever and empty the temp

    (4)use your simple randomness to select 2 indices (it does not matter if they are the same)

    (5)now swap the contents of the array aboutusing the 2 indices and the temp structure... in whatever language you like a->t b->a t->b

    (6)do this a whole lot of times (more than the number of random entries)

    (7)now output the array in order and you will be presented with an absolutely complete set of things in a random order with absolutely no repetition

    if you are just wanting to randomise the question order I would simple put the questions in the array as strings

    hope this helps

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Better train people and risk they leave – than do nothing and risk they stay.” - Anonymous