# Random Numbers and Random Strings

Page 1 of 1

## 2 Replies - 822 Views - Last Post: 24 November 2009 - 10:07 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=141364&amp;s=5bc6339e5b7a4d9960b871518b481789&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 CheckersW

Reputation: 12
• Posts: 198
• Joined: 04-April 09

# Random Numbers and Random Strings

Posted 24 November 2009 - 06:01 PM

Hi. I don't take programming lessons at school or anything, and I'm starting to (try to) teach myself about random things.

Currently I'm making an app that has 3 functions:

Random Integer (1 to 100)
Random Answer (Yes or No, similar to a coin flip)
Random Dice Roll (1 to 6)

How would I go about doing this?

At the moment all I know about random numbers etc. is that I will need to do something along the lines of

```Dim dice As New Random

```

or something like that, but, like I mentioned, I have no idea.

Could somebody point me in the right direction?

I am well aware of the DIC rules that you won't write the code for me/do my "homework(?)" for me, and that's not what I'm asking. I want to learn, and if that involves code, that would be great, but I'm sorry, I just don't have any code to show because I'm just here to learn.

Is This A Good Question/Topic? 0

## Replies To: Random Numbers and Random Strings

### #2 piman314

Reputation: 32
• Posts: 169
• Joined: 07-August 09

## Re: Random Numbers and Random Strings

Posted 24 November 2009 - 06:26 PM

the only methods you really need for this is Random.next. the first parameter is the noninclusive maximum (so if you give 10 as a max it will give you a number from 0 to 9). So for the first one you would want 100 as a max and then add one afterwards. for the second one you want 2 as a maximum, and then you can directly convert it to a boolean (1 is true and 0 is false). the third one you would just use 6 as a max and add 1.
```Dim rand As New Random()
Dim rand100 As Integer= rand.Next(100) + 1
Dim randdecision As Boolean = rand.Next(2)
Dim randdice As Integer = rand.Next(6) + 1

```

### #3 CheckersW

Reputation: 12
• Posts: 198
• Joined: 04-April 09

## Re: Random Numbers and Random Strings

Posted 24 November 2009 - 10:07 PM

Perfect. That works fine. Thanks for making it all so simple for me.