Link to home
Start Free TrialLog in
Avatar of gummisj
gummisj

asked on

RANDOM in function

Hi guys, i have one question, how can i add random to this function here below? is it poseble to add the random somewhere there inside? if so? please help asap, it is 500 pt for this. i need it fast, or do you need something more to this can be done?
private string DeliverThjonPages()
		{
 
			
			if( Query == null )
				return "";
			
			//if( cp > 1 )
			//	return "";	
 
			string pages = "";
 
			
		  	int min = (cp - 1) * 12;
			int max = ((cp - 1) * 12) + 12;
			int counter = 0;
 
			if( ThjonPages.Contains( Query.ToLower().Trim() ) )
			{
				DataTable resTable = (DataTable) ThjonPages[Query.ToLower().Trim()]; //Cleaned
				DataRow[] results = resTable.Select("","Date_Created");
 
				if(results.Length < min)
					AreThjonResults = false;
 
				foreach( DataRow dr in results )		
				{
					if(counter >= min & counter < max)
					{
						pages += MakeThjonPage(dr);
						AreThjonResults = true;
					}
					counter++;
				}
				resTable.Dispose();
			}
			return pages;

Open in new window

Avatar of Beholdason
Beholdason
Flag of United Kingdom of Great Britain and Northern Ireland image

If you could remind me what programming language you are using i would be able to answer your question
Avatar of gummisj
gummisj

ASKER

sorry. this is C#. i am newby in this and dont know much in this. i am trying my best  :)
int RandomNumber = RandomClass.Next();

The value of RandomNumber will, therefore, be assigned a random whole number between 1 and 2,147,483,647.

int RandomNumber = RandomClass.Next(4, 14);

The value of RandomNumber will, therefore, be assigned a random whole number between 4 and 14.

int RandomNumber = RandomClass.Next(100);

The value of RandomNumber will, therefore, be assigned a random whole number between 0 and 100.

double RandomNumber = RandomClass.NextDouble();

As well as returning random integers, the Random class can also return floating point numbers. The NextDouble method returns a random number as a Double. The random number's value is always greater or equal to 0.0, and less than 1.0:
Avatar of gummisj

ASKER

Ok, i am wondering if i can change this code here below that is showing 12 ads by ID and let it still do that but in random order? can i do that and how if so ?
int min = (cp - 1) * 12;
int max = ((cp - 1) * 12) + 12;
int counter = 0;

Open in new window

I am not sure so the question or of want is the program is really doing but i'll hazard a guess

i would try something along the lines of
int min = (cp - 1) * 12;
int max = ((cp - 1) * 12) + 12;
int random = 0;
int amount = max - min;
 if(random < (max - min)
{
 
int RandomNumber = RandomClass.Next(min, max);
 
}
int counter = 0;

Open in new window

Avatar of gummisj

ASKER

I got an error there. also complaning about "RandomClass.Next" what is that?
Compilation Error 
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 
 
Compiler Error Message: CS1026: ) expected
 
Source Error:
Line 1672:int random = 0;
Line 1673:int amount = max - min;
Line 1674: if(random < (max - min)   <--- this line
Line 1675:{
Line 1676:
 

Open in new window

Avatar of gummisj

ASKER

BTW. this is .net 1.1, if that metter some how.
Sorry i am being stupid

heres the corrected version
int min = (cp - 1) * 12;
int max = ((cp - 1) * 12) + 12;
int random = 0;
int amount = max - min;
 if(random < amount)
{
 
int RandomNumber = RandomClass.Next(min, max);
 
}
int counter = 0;

Open in new window

Avatar of gummisj

ASKER

Hi again, "'RandomClass' could not be found"  how do i add the random class? is this inside the framework version 1.1?

 
Compilation Error 
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 
 
Compiler Error Message: CS0246: The type or namespace name 'RandomClass' could not be found (are you missing a using directive or an assembly reference?)
 
Source Error:
 
 
 
Line 1675:{
Line 1676:
Line 1677:int RandomNumber = RandomClass.Next(min, max);
Line 1678:
Line 1679:}
 

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Juan_Barrera
Juan_Barrera
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
add this snippet maybe

I take none of the credit just noticed thats this was still open got the information off Juan Barrera
[SerializableAttribute]
[ComVisibleAttribute(true)]
public class Random

Open in new window