Randomize problem...

Hi I have randomize question...

Let's say I have a string that says 'ABCDE' now I want this string to change into a random string containing all these 5 letters.

Thx MTy

Comments

  • [b][red]This message was edited by Manning at 2004-4-26 17:25:0[/red][/b][hr]
    : Hi I have randomize question...
    :
    : Let's say I have a string that says 'ABCDE' now I want this string to change into a random string containing all these 5 letters.

    Does it have to use those letters and stay that length? If so, I might do it this way (first thing that came to my mind):

    [code]
    input string = 'ABCDE'
    output string = ''
    loop while input string is not null
    Pick a random number between 1 and length of input string
    Copy the character at the position of the random number from the
    input string and append it to the output string
    Delete the character at the position of the random number
    in the input string
    end loop
    [/code]

    So the loop will pick a random character, put it into the new random string, and then delete it from the input string (this step assumes you don't want duplicates). Once you delete all the characters from the input string, the loop terminates and you'll have your random string in the output string.


  • [code]
    input string = 'ABCDE'
    output string = ''
    loop while input string is not null
    Pick a random number between 1 and length of input string
    [red]if (random number not deleted) then begin[/red]
    Copy the character at the position of the random number from the
    input string and append it to the output string
    Delete the character at the position of the random number
    in the input string
    [red]end;[/red]
    end loop
    [/code]

    don't forget that!
  • : [code]
    : input string = 'ABCDE'
    : output string = ''
    : loop while input string is not null
    : Pick a random number between 1 and length of input string
    : [red]if (random number not deleted) then begin[/red]
    : Copy the character at the position of the random number from the
    : input string and append it to the output string
    : Delete the character at the position of the random number
    : in the input string
    : [red]end;[/red]
    : end loop
    : [/code]
    :
    : don't forget that!
    :

    You may forget "[red]that[/red]" courageously because you "Delete the character at the position of the random number in the input string" at every cycle end ... and by reason of this the new random number will be selected from a shorter and shorter string, automatically.

  • : : [code]
    : : input string = 'ABCDE'
    : : output string = ''
    : : loop while input string is not null
    : : Pick a random number between 1 and length of input string
    : : [red]if (random number not deleted) then begin[/red]
    : : Copy the character at the position of the random number from the
    : : input string and append it to the output string
    : : Delete the character at the position of the random number
    : : in the input string
    : : [red]end;[/red]
    : : end loop
    : : [/code]
    : :
    : : don't forget that!
    : :
    :
    : You may forget "[red]that[/red]" courageously because you "Delete the character at the position of the random number in the input string" at every cycle end ... and by reason of this the new random number will be selected from a shorter and shorter string, automatically.


    I'm glad someone understood :-)
  • : : : [code]
    : : : input string = 'ABCDE'
    : : : output string = ''
    : : : loop while input string is not null
    : : : Pick a random number between 1 and length of input string
    : : : [red]if (random number not deleted) then begin[/red]
    : : : Copy the character at the position of the random number from the
    : : : input string and append it to the output string
    : : : Delete the character at the position of the random number
    : : : in the input string
    : : : [red]end;[/red]
    : : : end loop
    : : : [/code]
    : : :
    : : : don't forget that!
    : : :
    : :
    : : You may forget "[red]that[/red]" courageously because you "Delete the character at the position of the random number in the input string" at every cycle end ... and by reason of this the new random number will be selected from a shorter and shorter string, automatically.
    :
    :
    : I'm glad someone understood :-)
    :

    Thx y'all
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories