User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 401,589 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,653 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 393 | Replies: 1
Reply
Join Date: Oct 2007
Posts: 13
Reputation: acwbrat is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
acwbrat acwbrat is offline Offline
Newbie Poster

Code-Behind Files coding for random numbers

  #1  
May 5th, 2008
I am very new to ASP.net and never used this feature before. I am trying to generate a code that will generate random numbers. The numbers must be in the range from 10-100. This is what I have generated. However, I am still running into some difficulty.


// test.aspx.cs
// The code behind file for test.aspx
// Includes a function to build an array of ten pseudorandom
// numbers
using System;
using System.Web;
using System.Web.UI;
public class test : Page
{
    // Build a pseudorandom number method
    System.Random RandNum = new System.Random();
    int MyRandomNumber = RandNum.Next(10, 100);
    protected int[] myArray = new int[10];
    // A method to fill the array with pseudorandom numbers
    public void fillArray()
    {
        for (int index = 0; index < 10; index++)
            // Generate a pseudorandom number in the range of 10 to 100
            myArray[index] = randomGen.Next(10, 100);
    }
}


................................................

<!-- test.aspx
A simple example of an ASP.NET document with a code-behind file
It has the same functionality as test.aspx
-->

<%@ Page Language="C#" Inherits="test" Src="test.aspx.cs" %>

<html>
<head>
    <title>test</title>
</head>
<body>
    <!-- Code to call the fillArray method and display the array-->
    <% string msg;
       fillArray();
       Response.Write(
       "<br /> <b>The array’s contents are: </b><br /><br />");
       for (int index = 0; index < 10; index++)
       {
           msg = string.Format("The element at {0} is: {1} <br />",
           index, myArray[index]);
           Response.Write(msg);
       }
    %>
</body>
</html>
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2007
Location: Bristol, UK
Posts: 1,124
Reputation: majestic0110 is on a distinguished road 
Rep Power: 3
Solved Threads: 47
majestic0110's Avatar
majestic0110 majestic0110 is offline Offline
Veteran Poster

Re: Code-Behind Files coding for random numbers

  #2  
May 6th, 2008
What is the difficulty you are having (Specifically).
If you have a quality, be proud of it and let it define you. Add it to the world!
If you got your answer, please mark the thread as Solved. It saves time when people are looking to contribute threads or for answers!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb ASP.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 4:39 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC