Click here to Skip to main content
16,011,956 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Sorting and keeping an index Pin
Dave Kreskowiak29-Dec-06 10:39
mveDave Kreskowiak29-Dec-06 10:39 
AnswerRe: Sorting and keeping an index [modified] Pin
CPallini29-Dec-06 23:51
mveCPallini29-Dec-06 23:51 
Questionconnection string Pin
jds120729-Dec-06 10:26
jds120729-Dec-06 10:26 
AnswerRe: connection string Pin
Dave Kreskowiak29-Dec-06 10:37
mveDave Kreskowiak29-Dec-06 10:37 
AnswerRe: connection string Pin
Paul Conrad29-Dec-06 10:38
professionalPaul Conrad29-Dec-06 10:38 
QuestionName Backwards Pin
shotgun2129-Dec-06 10:13
shotgun2129-Dec-06 10:13 
AnswerRe: Name Backwards Pin
KevinMac29-Dec-06 13:45
KevinMac29-Dec-06 13:45 
QuestionGenerating random numbers Pin
UncleMikey29-Dec-06 8:15
UncleMikey29-Dec-06 8:15 
I have just completed a course in programming VB.NET with DeVry and I really like it. I want to write a program for a blackjack game. I have 2 arrays set up for the deck of cards, one for the card name (ex. 3-Hearts) and the other for the card value (ex. the 3-Hearts = 3).

I'm starting small and I only want to deal 2 hands (user and dealer). My question is:

Is there a better way to generate 4 random numbers from 1 - 52 so that you do not get the same number twice? Of course, for drawing other cards in the hand I'll need additional random numbers.

This is what I have and it seems to work, but is there another (better, shorter) way?

Randomize() 'Initialize random number generator.
Do
intCard1 = CInt(Int((51 - 0 + 1) * Rnd() + 0)) 'Random generate 1st number.
intCard2 = CInt(Int((51 - 0 + 1) * Rnd() + 0)) 'Random generate 2nd number.
Loop Until intCard1 <> intCard2 'Loop if cards are the same.
Do
intCard3 = CInt(Int((51 - 0 + 1) * Rnd() + 0)) 'Random generate 3rd number.
Loop Until intCard3 <> intCard1 And intCard3 <> intCard2
Do
intCard4 = CInt(Int((51 - 0 + 1) * Rnd() + 0)) 'Random generate 4th number.
Loop Until intCard4 <> intCard1 And intCard4 <> intCard2 And intCard4 <> intCard3

Thanks in advance for any assistance!
Mike
AnswerRe: Generating random numbers Pin
CPallini29-Dec-06 8:36
mveCPallini29-Dec-06 8:36 
QuestionRe: Generating random numbers Pin
UncleMikey29-Dec-06 9:57
UncleMikey29-Dec-06 9:57 
AnswerRe: Generating random numbers Pin
CPallini29-Dec-06 10:13
mveCPallini29-Dec-06 10:13 
QuestionProgram wont run; already Published and installed Pin
Karma3125129-Dec-06 4:30
Karma3125129-Dec-06 4:30 
AnswerRe: Program wont run; already Published and installed Pin
Dave Kreskowiak29-Dec-06 9:26
mveDave Kreskowiak29-Dec-06 9:26 
GeneralRe: Program wont run; already Published and installed Pin
Karma3125129-Dec-06 9:29
Karma3125129-Dec-06 9:29 
GeneralRe: Program wont run; already Published and installed Pin
Dave Kreskowiak29-Dec-06 9:36
mveDave Kreskowiak29-Dec-06 9:36 
GeneralRe: Program wont run; already Published and installed Pin
Karma3125129-Dec-06 9:39
Karma3125129-Dec-06 9:39 
GeneralRe: Program wont run; already Published and installed Pin
Dave Kreskowiak29-Dec-06 15:04
mveDave Kreskowiak29-Dec-06 15:04 
QuestionCan I run vb or com components Pin
indian14329-Dec-06 1:58
indian14329-Dec-06 1:58 
AnswerRe: Can I run vb or com components Pin
Dave Kreskowiak29-Dec-06 3:25
mveDave Kreskowiak29-Dec-06 3:25 
QuestionDataGridView doesnot update in vb.net 2005 Express Edition Pin
Dharmit29-Dec-06 1:31
Dharmit29-Dec-06 1:31 
NewsHiEdit V1.0.1.4 Pin
akyprian28-Dec-06 21:36
akyprian28-Dec-06 21:36 
GeneralRe: HiEdit V1.0.1.4 Pin
Dave Kreskowiak29-Dec-06 3:24
mveDave Kreskowiak29-Dec-06 3:24 
GeneralRe: HiEdit V1.0.1.4 Pin
akyprian29-Dec-06 4:13
akyprian29-Dec-06 4:13 
GeneralRe: HiEdit V1.0.1.4 Pin
CPallini29-Dec-06 6:08
mveCPallini29-Dec-06 6:08 
GeneralRe: HiEdit V1.0.1.4 Pin
akyprian29-Dec-06 6:50
akyprian29-Dec-06 6:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.