Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

VB 2010 Express - Choosing an array value NOT chosen previously

$
0
0
I'm using Visual Basic 2010 Express.

Okay, here's my issue. I'm making a program that encrypts text so that my friends and I can mess around with secret messages in school (yeah, it's sad, but I think it'll be good practice for coding :P/>). I have an array of 251 strings. I want my program to choose a random one of these strings, but NOT one of them that was already selected previously. I've been trying to use a random number generator for the last few hours, but that won't work with the limited knowledge I have now.

This is my code:
 generator_counter = 1

        Do While generator_counter <= Len(input_text)

            'this is my random number generator; it randomly chooses one of 251 values.
            Randomize()
            rdm_select = Int(Rnd() * 250)


            'my thinking was this: If I can make it choose a random number BUT NOT A NUMBER IT CHOSE ALREADY, this would work:

                output_code = output_code + (Mid(input_text, generator_counter, 1) = code_chars(rdm_select))

            'I figure there has to be a way to, without the random number generator, make it choose a random string from the
            'array that was not already used; giving me (in words, not code):
            'output_code = output_code + [a value from the array not used previously]

            generator_counter = generator_counter + 1
        Loop


Can anyone, please, explain to me how to do one of these two things:
  • Make a random number generator NOT choose a previously chosen number (without a DO WHILE loop)
  • Make the program select one of the strings in the array randomly, but NOT one chosen previously


I deleted the code I had before, because it wasn't gonna work. It involved a convoluted process that, even if I had made it work, would just result in it going around the DO WHILE over and over until the random number generator generated a number that hadn't been used before. Ignore the fact that all of this is inside a DO WHILE; that's crucial to the program and shouldn't affect what I need to do.

tl;dr: The most helpful thing would be for someone to teach me how to make a random number generator not choose a number chosen previously.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>