# Coin flip in visual basic

• ### Question

• G hvjbjvj
Wednesday, September 30, 2020 2:15 AM

### All replies

• What does your code do? It generates 2 random numbers, both of which are within the range you specify. Adding them together does nothing useful. E.g., if your random numbers were 34 and 411, the total (34 + 411 = 445) is highly unlikely to ever be 1000 directly (and that is not your goal anyways).

Your goal is to simulate flipping a coin 1000 times. To simulate the flipping part, you generate a random number between 0 and 1 (or any similar 2-value range) where one of the values represents tails and one represents heads. You then do this in a loop 1000 times, counting (not summing) the number of times the coin lands heads-up or tails-up.

• Edited by Wednesday, September 30, 2020 2:45 AM again 1000
Wednesday, September 30, 2020 2:44 AM
• Thanks for the reply! Could you show an example?
Wednesday, September 30, 2020 3:04 AM
•  Could you show an example?

As a program such as this is usually a course assignment, we should not be

Giving a code example for a small task such as this amounts to providing the
complete solution.

Think about the task. Write some code. See what it does. See what it doesn't
do. If you get stuck at some point, post your new code with a description
of the new problems with it. We'll then try to steer you toward a solution
without doing the coding for you.

- Wayne

Wednesday, September 30, 2020 4:52 AM
• I agree with WayneAKing about course assignment, I just give you a little help.

If in 1000 flips you have n heads, you have 1000-n tails and the sum is the number of flips, i.e. 1000.

If you simulate the 1000 filps with heads = random number (0 to 1000) and tails = 1000-heads, you have a result.

If you simulate the 1000 flips with 1000 random numbers (0 or 1) with 0 = head and 1 = tail, you have another result.

Are the 2 procedures equivalent from the statistical simulation point of view?

It's better to use the first or the secondo one, or it's the same?

Think about the expected values, about how random generator works and about the definition of frequency and what is frequency when you have infinite flips.

Wednesday, September 30, 2020 7:03 AM
• Homework? Then look at the following code sample in C# (it's easy enough to convert)

https://dotnetfiddle.net/Tiquhk

Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

NuGet BaseConnectionLibrary for database connections.

StackOverFlow

Wednesday, September 30, 2020 12:53 PM
• @redraider29003,

We will not be assisting you in the future if this is how you are in regards to present yourself in regards to asking a question then removing the text of the question. This is uncalled for period.

Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

NuGet BaseConnectionLibrary for database connections.

StackOverFlow

Wednesday, September 30, 2020 7:13 PM