I've been try to make an encryption app that makes a full randomized list based off special characters based off a database of random characters but I don't know how to make the code that makes the randomized list. I've been try to pull from the list directly and then delete the item that was chosen. From there I would repeat it for the amount of letters there are in the alphabet and then display it but I keep on getting error messages. Any way for someone to help?
How do I make a randomized list that doesn't pick the same value from a database?
Part of your problem stems from not naming your variables to include their type and purpose in their names.
For example global name2 should be SelectedItemsList.
That would give you the hint needed to see that it should start out as an empty list and that at every loop you would be adding an item to it, instead of replacing its value.
Also, rename that procedure8 to PopulateSelectedItemsList.
Ai2 has had bugs where it messes up procedures whose names have not been updated to get them out of the way of its autonaming engine.
Finalyy, naming is important.
I'm sorry I don't understand when you mean the list needs to start out empty can you tell me in more detail? Also I did change the names and I does say my code is wrong so can you let me know what exactly is wrong with it? Sorry for the trouble
To get an empty list, use the CREATE EMPTY LIST block.
It is important that you learn what you are doing and not just copy some blocks from another user, so you can come up with your own solutions in the future. Please read this little tutorial carefully and try to understand each step, then ask if you don't understand something.
You should start by painting a picture in your head of what you would do if you had to do the same thing but with cards.
You would be moving random cards from stack 1 to stack 2 until there's no more cards in stack 1, right?
Then look in the LISTS section of the blocks palette and try to come up with a procedure that does that using the blocks that you have there.
For example, the first thing you need to do is to select a random card from stack 1, so we have the PICK A RANDOM ITEM block which will do that.
And we also have an ADD ITEMS TO LIST block. With those two blocks we can actually COPY a random card from stack 1 to stack 2.
But to make sure next time we don't select that same card from stack 1, we need to REMOVE that card from stack 1. We also have a block for that. Do you know which one is? Exactly.
But there's a problem, we have to know the position of the card we need to remove from stack 1.
So we go back to see what blocks we have available and we see that there's an INDEX IN LIST block.
We will use that block this way:
The THING will be the LAST item we added to stack 2. And the LIST will be stack 1 of course.
How do we get the last item of a list? Easy:
The blocks are very self explanatory.
So putting all that together it would look like this:
These blocks above will select one random item from stack 1 and MOVE IT to stack 2.
But we need to repeat this same process for as many cards or items we have in stack 1.
So we can wrap this in a loop that will check every time if stack 1 is empty. If it's NOT empty, then it will repeat the process. And if it is empty, it will stop.
When this loop ends, stack 1 will be empty and stack 2 will have all the items from stack 1 but shuffled or mixed.
Don't worry I did learn form this experience and now know that I was unable to view the code correctly but I also learned that lists can used much more ways than I thought and I'll study this more.
I propose to simplify this process . You can first get a random index in the range from 1 to the length of the first list. Then copy the corresponding element to the second list. After that, remove it from the first list. I used this method in my design. It works well.
Good method! If possible I always try to do processes without having to create variables if the value can be retrieved from somewhere else. Is just my way of doing it and yes, sometimes that complicates it a little. Nothing wrong with creating a variable for the index. Thanks.
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.