473,396 Members | 2,109 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

'Continue loop until all variables have different values'. How?

Hi, I'm creating a Tarot card randomizer in VB.net just for an excersize of trying to remain faithful to random while still using certain rules - like no duplicate values. Here's the code. I've attempted to do this already as you can see from the code but the program simply stops half way through.
I've also tried the same code with just one do-while loop surrounding all of the for-next loops and this simply doesn't work - there are duplicates in the values. I've put in the whole code just incase.

Expand|Select|Wrap|Line Numbers
  1.     Private Sub btndeal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndeal.Click
  2.  
  3.         Dim rnum As Integer
  4.         Dim cardmeanings(21) As String
  5.         Dim card1num As Integer
  6.         Dim card2num As Integer
  7.         Dim card3num As Integer
  8.         Dim card4num As Integer
  9.         Dim card5num As Integer
  10.         Dim card6num As Integer
  11.         Dim card7num As Integer
  12.         Dim card8num As Integer
  13.         Dim card9num As Integer
  14.         Dim card10num As Integer
  15.  
  16.         cardmeanings(0) = "The Fool: At #0, the Fool is the card of infinite possibilities. The bag on the staff indicates that he has all he needs to do or be anything he wants, he has only to stop and unpack. He is on his way to a brand new beginning. But the card carries a little bark of warning as well. Stop daydreaming and fantasizing and watch your step, lest you fall and end up looking the fool."
  17.         cardmeanings(1) = "The Magician: At #1, the Magician is the male power of creation, creation by willpower and desire. You might well interpret that you will be given a vision, an idea, a magical - mental image of whatever it is you most want: the solution to a problem, an ambitious career, a love life, a job."
  18.         cardmeanings(2) = "The High Priestess: The High Priestess is the card of secret or arcane knowledge. She holds scrolls of arcane information that she might reveal to you. The moon crown on her head indicates her willingness to illuminate what you otherwise might not see, reveal the secrets you need to know in order to make a decision."
  19.         cardmeanings(3) = "The Empress: The Empress is a creator, be it creation of life, of romance, of art or business. While the Magician is the primal spark, the idea made real, and the High Priestess is the one who gives the idea a form, the Empress is the womb where it gestates and grows till it is ready to be born."
  20.         cardmeanings(4) = "The Emporer: The Emperor card is the 'Who's the boss?' card. It is an important question. The meaning of the card includes being in control over your environment, your body, your temper, your instincts, your love life. This is not the time to give into the unconscious, not the time to let yourself be controlled by the wants and needs of others. It is a card that gives the Querent permission to be aggressive, brave, bold and in command."
  21.         cardmeanings(5) = "The Hierophant: the Hierophant might well warn against being too stubborn, especially in matters of theology or ethics. He can remind the Querent what it means to be a good and beloved teacher. In this, the Hierophant can be very positive. When things are going very wrong in the world, the Hierophant is the one who wades in, quiets the panic, and offers good, practical advice."
  22.         cardmeanings(6) = "The Lovers: LOVE is a force that makes you choose and decide for reasons you often can't understand; it makes you surrender control to a higher power. And that is what this card is all about. Finding something or someone who is so much a part of yourself, so perfectly attuned to you and you to them, that you cannot, dare not resist. In interpretation, the card indicates that the querent has come across, or will come across a person, career, challenge or thing that they will fall in love with."
  23.         cardmeanings(7) = "The Chariot: On the one hand, the Chariot indicates loyalty and faith and motivation; a conviction that will lead to victory no matter the odds. But the chariot can also signal a ruthless, diehard desire to win at any cost. The Querent should be reminded to save his/her energy for what comes after. Victory is just the start of things."
  24.         cardmeanings(8) = "Strength: You might get burned or scratched a few times by that which you're trying to control, be it a situation, a person or your own unworthy impulses. The important message of the strength card is not to give up. To have the courage to keep at it till you succeed and to have the faith and optimism that you will succeed."
  25.         cardmeanings(9) = "The Hermit: the Hermit represents a wise, inspirational person, friend, teacher, therapist, someone the Querent usually sees alone, someone the rest of the Querent's friends and family may not know about. This a person who can shine a light on things that were previously mysterious and confusing. They will help the Querent find what it is they are seeking."
  26.         cardmeanings(10) = "The Wheel of Fortune: With Jupiter as its ruling planet, the Wheel of Fortune is all about big things, luck, change, and fortune. Almost always good fortune. Almost every definition of this card indicates abundance, happiness, elevation, or luck; a change that just happens, and brings with it great joy."
  27.         cardmeanings(11) = "Justice: With Libra as its ruling sign, Justice is about cold, objective balance through reason or natural force. This is the card that tells the Querent that they can't keep smoking and drinking without consequences to their health. It is the card that advises cutting out waste and insists that the Querent make adjustments, do whatever is necessary to bring things back into balance: physically, emotionally, socially, spiritually."
  28.         cardmeanings(12) = "The Hangman: He makes himself vulnerable, sacrifices his position or opposition, and in doing so, gains illumination. Answers that eluded him become clear, solutions to problems are found. He sees the world differently, has almost mystical insights. This card can also imply a time when everything just stands still, a time of rest and reflection before moving on."
  29.         cardmeanings(13) = "Death: The Death card indicates this transition from lower to higher to highest. This is a card of humility, and it may indicate the Querent as being brought low, but only so that they can then go higher than they ever have before. This is a time of change. Time for something to end; but time also for something new to begin. The Querent may honestly be told that they may feel sad or empty, low, but that this will give him a way to rise again, like a phoenix from the ashes."
  30.         cardmeanings(14) = "Temperance: Temperance may be, at first glance, a warning to the Querent to 'temper' their behavior, to cut their wine with water. But it may also be a reminder to the Querent that seemingly irreconcilable opposites may not be irreconcilable at all."
  31.         cardmeanings(15) = "The Devil: this is a card about ambitions; it is also synonymous with temptation and addiction. On the flip side, however, the card can be a warning to someone who is too restrained, someone who never allows themselves to get passionate or messy or wild - or ambitious. This, too, is a form of enslavement."
  32.         cardmeanings(16) = "The Tower: When the Querent gets this card, they can expect to be shaken up, to be blinded by a shocking revelation. It sometimes takes that to see a truth that one refuses to see. Or to bring down beliefs that are so well constructed. However painful, makes room for something new to be built."
  33.         cardmeanings(17) = "The Star: The Star is a card that looks to the future. It does not predict any immediate or powerful change, but it does predict hope and healing. This card suggests clarity of vision, spiritual insight. And, most importantly, that unexpected help will be coming, with water to quench the Querent's thirst."
  34.         cardmeanings(18) = "The Moon: this is a card of great creativity, of powerful magic, primal feelings and intuition. The Querent who gets this card should be warned that they may be going through a time of emotional and mental trial; if they have any past mental problems, they must be vigilant in taking their medication. They should avoid drugs or alcohol"
  35.         cardmeanings(19) = "The Sun: A positive card, it promises the Querent their day in the sun. Glory, gain, triumph, pleasure, truth, success. As the moon symbolized inspiration from the unconscious, from dreams, this card symbolizes discoveries made fully conscious and wide awake. This is science and math, beautifully constructed music, carefully reasoned philosophy."
  36.         cardmeanings(20) = "Judgement: Judgement is often a hard card to read; it usually signals just a big change, one that involves leaving something old completely behind and stepping into something completely new. Like closing the door on an old job, and opening the door to a new and very different career."
  37.         cardmeanings(21) = "The World: the World card, very aptly, represents a successful conclusion, all aspects accounted for and taken in. Simply put, this card tells the Querent that the end to a long-term project is in sight, and that it will be accompanied by well-earned praise, celebration and success. With Saturn as its ruling planet, this card can also indicate that the Querent, now an expert in their subject, is likely to become a teacher or sought-after lecturer."
  38.  
  39.  
  40.         Do Until card1num <> card2num And card1num <> card3num And card1num <> card4num And card1num <> card5num And card1num <> card6num And card1num <> card7num And card1num <> card8num And card1num <> card9num And card1num <> card10num
  41.             For rnum = 1 To 21
  42.                 card1num = Math.Round(Rnd() * 21)
  43.             Next rnum
  44.         Loop
  45.  
  46.         Do Until card2num <> card1num And card2num <> card3num And card2num <> card4num And card2num <> card5num And card2num <> card6num And card2num <> card7num And card2num <> card8num And card2num <> card9num And card2num <> card10num
  47.             For rnum = 1 To 21
  48.                 card2num = Math.Round(Rnd() * 21)
  49.             Next rnum
  50.         Loop
  51.  
  52.         Do Until card3num <> card1num And card3num <> card2num And card3num <> card4num And card3num <> card5num And card3num <> card6num And card3num <> card7num And card3num <> card8num And card3num <> card9num And card3num <> card10num
  53.             For rnum = 1 To 21
  54.                 card3num = Math.Round(Rnd() * 21)
  55.             Next rnum
  56.         Loop
  57.  
  58.         Do Until card4num <> card1num And card4num <> card2num And card4num <> card3num And card4num <> card5num And card4num <> card6num And card4num <> card7num And card4num <> card8num And card4num <> card9num And card4num <> card10num
  59.             For rnum = 1 To 21
  60.                 card4num = Math.Round(Rnd() * 21)
  61.             Next rnum
  62.         Loop
  63.  
  64.         Do Until card5num <> card1num And card5num <> card2num And card5num <> card3num And card5num <> card4num And card5num <> card6num And card5num <> card7num And card5num <> card8num And card5num <> card9num And card5num <> card10num
  65.             For rnum = 1 To 21
  66.                 card5num = Math.Round(Rnd() * 21)
  67.             Next rnum
  68.         Loop
  69.  
  70.         Do Until card6num <> card1num And card6num <> card2num And card6num <> card3num And card6num <> card4num And card2num <> card5num And card6num <> card7num And card6num <> card8num And card6num <> card9num And card6num <> card10num
  71.             For rnum = 1 To 21
  72.                 card6num = Math.Round(Rnd() * 21)
  73.             Next rnum
  74.         Loop
  75.  
  76.         Do Until card7num <> card1num And card6num <> card2num And card6num <> card3num And card6num <> card4num And card2num <> card5num And card6num <> card6num And card6num <> card8num And card6num <> card9num And card6num <> card10num
  77.             For rnum = 1 To 21
  78.                 card7num = Math.Round(Rnd() * 21)
  79.             Next rnum
  80.         Loop
  81.  
  82.         Do Until card8num <> card1num And card6num <> card2num And card6num <> card3num And card6num <> card4num And card2num <> card5num And card6num <> card6num And card6num <> card7num And card6num <> card9num And card6num <> card10num
  83.             For rnum = 1 To 21
  84.                 card8num = Math.Round(Rnd() * 21)
  85.             Next rnum
  86.         Loop
  87.  
  88.         Do Until card9num <> card1num And card6num <> card2num And card6num <> card3num And card6num <> card4num And card2num <> card5num And card6num <> card6num And card6num <> card7num And card6num <> card8num And card6num <> card10num
  89.             For rnum = 1 To 21
  90.                 card9num = Math.Round(Rnd() * 21)
  91.             Next rnum
  92.         Loop
  93.  
  94.         Do Until card10num <> card1num And card6num <> card2num And card6num <> card3num And card6num <> card4num And card2num <> card5num And card6num <> card6num And card6num <> card7num And card6num <> card8num And card6num <> card9num
  95.             For rnum = 1 To 21
  96.                 card10num = Math.Round(Rnd() * 21)
  97.             Next rnum
  98.         Loop
  99.  
  100.         card1.Load("C:\Documents and Settings\ScottInstrell\Desktop\Tarotech1\Tarotechpics\" & card1num & ".jpg")
  101.         card2.Load("C:\Documents and Settings\ScottInstrell\Desktop\Tarotech1\Tarotechpics\" & card2num & ".jpg")
  102.         card3.Load("C:\Documents and Settings\ScottInstrell\Desktop\Tarotech1\Tarotechpics\" & card3num & ".jpg")
  103.         card4.Load("C:\Documents and Settings\ScottInstrell\Desktop\Tarotech1\Tarotechpics\" & card4num & ".jpg")
  104.         card5.Load("C:\Documents and Settings\ScottInstrell\Desktop\Tarotech1\Tarotechpics\" & card5num & ".jpg")
  105.         card6.Load("C:\Documents and Settings\ScottInstrell\Desktop\Tarotech1\Tarotechpics\" & card6num & ".jpg")
  106.         card7.Load("C:\Documents and Settings\ScottInstrell\Desktop\Tarotech1\Tarotechpics\" & card7num & ".jpg")
  107.         card8.Load("C:\Documents and Settings\ScottInstrell\Desktop\Tarotech1\Tarotechpics\" & card8num & ".jpg")
  108.         card9.Load("C:\Documents and Settings\ScottInstrell\Desktop\Tarotech1\Tarotechpics\" & card9num & ".jpg")
  109.         card10.Load("C:\Documents and Settings\ScottInstrell\Desktop\Tarotech1\Tarotechpics\" & card10num & ".jpg")
  110.  
  111.  
  112.     End Sub
  113.  
Oct 22 '10 #1
1 1339
Joseph Martell
198 Expert 128KB
what if you created a pool of numbers: 1 - 21 and then chose a random selection from the pool? Something like the following:

Expand|Select|Wrap|Line Numbers
  1.         'create a pool of numbers that you know are unique
  2.         Dim numberPool As New List(Of Integer)(21)
  3.         For i As Integer = 1 To 21
  4.             numberPool.Add(i)
  5.         Next
  6.  
  7.         Dim generator As New Random()
  8.  
  9.         Dim cardNums(10) As Integer    'the 10 cards that you are drawing
  10.         Dim numPoolIndex As Integer = 0
  11.  
  12.         For i As Integer = 0 To cardNums.Count
  13.             'choose a random number from the number pool (by choosing a random index)
  14.             numPoolIndex = generator.Next(0, numberPool.Count - 1)
  15.  
  16.             'use the random index created above to select the card number from your number pool
  17.             cardNums(i) = numberPool(numPoolIndex)
  18.  
  19.             'remove the selected number from the number pool.  
  20.             'This ensures that a particular number will never be drawn twice.
  21.             numberPool.RemoveAt(numPoolIndex)
  22.         Next
  23.  
This gets rid of those messy if statements and all of those loops.
Oct 23 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Ronnie Laurikkala | last post by:
In e.g. a Bourne shell script I can source variables and values; #!/bin/sh .. ${HOME}/script_common_lib How can I source variables and values from a file and use them in Perl-scripts? ...
3
by: Alan | last post by:
Hi, is it possible to create a project that can offer different members of a Public Enum according to a condition ? I mean, Project A has a public enum. Project B & C access A's enum. However B...
0
by: Zamael | last post by:
Currently I have a dataset that populates as follows (example data): ID Cycle Drug_Day Name 3 1 1 Initial 3 1 15 Initial 3 2 1 Initial 3 2 15 Initial 3 3 1 ...
6
by: placid | last post by:
Hi all, Im using the cmd module and i have command that loops and keeps on printing text, what i want to be able to do is loop until the user presses a particular key, say Q/q ? I tried the...
2
by: Otto Wyss | last post by:
On a page of mine a user might submit data several time, which adds an entry to the history each time (similar as http://www.google.com/trends?q=iPod%2C+iPhone&ctab=0&geo=all&date=all). Yet later...
5
by: =?Utf-8?B?QW5kcmV3?= | last post by:
Hello, friends, I am testing our website (in 2003.net, c#) application. Sometimes there more values in Querystring, like ...
2
by: shogot99 | last post by:
Till here the info gotten is ok Loop Until strainfo = "" ScreenMNS.WaitHostQuiet (400) Second process Copy "B" & paste in "E" Range("B2:B600").Select
3
by: shalskedar | last post by:
I want to insert different values in each worksheet i.e every worksheet should 've different values.I tried the below code but i m not able to set the range for a particular worksheet For ex-For...
4
by: needanswer | last post by:
Is possible to have different values of combobox on the multi same form? Actually I want to make a multi same form, but with one combobox to set the authority. When different persons to use this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.