# find minimum value in random number array?

Page 1 of 1

## 7 Replies - 1776 Views - Last Post: 03 February 2013 - 07:53 AMRate 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=310998&amp;s=555fe1ffdda6ea0cbad751898785805e&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 harold12345

Reputation: 0
• Posts: 4
• Joined: 03-February 13

# find minimum value in random number array?

Posted 03 February 2013 - 07:09 AM

Hey

This is my code for my array,the array works and fills it with 10 random numbers but i am having great difficulty trying to find the minimum value in the array.

My array code is
```Random random = new Random();

int[] numbers = new int[10];

for (int i = 1; i < numbers.Length; i++)
{
numbers[i] = random.Next(1, 19);

Console.WriteLine(numbers[i]);
}

```

I have tried various methods and none seen to work. I am struggling to understand why this particular method doesn't work.

```int min = numbers.Min();
```

Any help would be greatly appreciated.

Is This A Good Question/Topic? 0

## Replies To: find minimum value in random number array?

### #2 Ryano121

• D.I.C Lover

Reputation: 1461
• Posts: 3,289
• Joined: 30-January 11

## Re: find minimum value in random number array?

Posted 03 February 2013 - 07:22 AM

I don't see why .Min() wouldn't work. What output are you getting?

### #3 harold12345

Reputation: 0
• Posts: 4
• Joined: 03-February 13

## Re: find minimum value in random number array?

Posted 03 February 2013 - 07:29 AM

I am just getting 0

instead of using the function is there another way of hard coding i can use?

### #4 tlhIn`toq

• Xamarin Cert. Dev.

Reputation: 6535
• Posts: 14,450
• Joined: 02-June 10

## Re: find minimum value in random number array?

Posted 03 February 2013 - 07:32 AM

harold12345, on 03 February 2013 - 08:09 AM, said:

I am struggling to understand why this particular method doesn't work.

```int min = numbers.Min();
```

Any help would be greatly appreciated.

Let's see your complete code where you are actually using this call. Because that should work.

### #5 harold12345

Reputation: 0
• Posts: 4
• Joined: 03-February 13

## Re: find minimum value in random number array?

Posted 03 February 2013 - 07:39 AM

okay i have put the complete code here, its a visual studio 2010 project, in the console.

```using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Random random = new Random();

int[] numbers = new int[10];

for (int i = 1; i < numbers.Length; i++)
{
numbers[i] = random.Next(1, 19);

Console.WriteLine(numbers[i]);
}

// 8. Find the minimun of the array in task 7 and print it

int min = numbers.Min();
Console.WriteLine("the mimimum value is: " + min);
}
}
}
```

### #6 andrewsw

• Unprocessable Entity

Reputation: 6592
• Posts: 26,824
• Joined: 12-December 12

## Re: find minimum value in random number array?

Posted 03 February 2013 - 07:47 AM

POPULAR

You are starting your loop from 1, whereas the array starts from 0, so the first item has a default value of 0 - and this is the minimum that you keep seeing.

```for (int i = 0; i < numbers.Length; i++)
```

This post has been edited by andrewsw: 03 February 2013 - 07:49 AM

### #7 tlhIn`toq

• Xamarin Cert. Dev.

Reputation: 6535
• Posts: 14,450
• Joined: 02-June 10

## Re: find minimum value in random number array?

Posted 03 February 2013 - 07:52 AM

Andrew for the win!! The crowd goes wild

{Best I could do since the +1 button is broken at the moment}

This post has been edited by tlhIn`toq: 03 February 2013 - 07:53 AM

### #8 harold12345

Reputation: 0
• Posts: 4
• Joined: 03-February 13

## Re: find minimum value in random number array?

Posted 03 February 2013 - 07:53 AM

ahhhhhh, thanks a lot for your help work perfectly now