how to change a random variable to double ?

This is a discussion on how to change a random variable to double ? within the C# Programming forums, part of the General Programming Boards category; Hello . I am newbe in C# and working on Randon type . a part of my code is : ...

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    177

    how to change a random variable to double ?

    Hello .
    I am newbe in C# and working on Randon type .
    a part of my code is :

    Code:
    Random r = new Random();
    Double R;
    for(int i=0;i<10;++i)
    {
         r.NextDouble();
         R=r;
    but I get an error in the "R=r;" line .
    is it possible to change a random variable to double ?

    thank you

  2. #2
    Registered User
    Join Date
    Nov 2003
    Posts
    177
    I forgot to say the goal .
    I have an array of double between 0-1 and want to do some operations on it depend on the generated random r , but I get error messages in those lines

    Code:
    for(int i=0;i<10;++i)
          {
    	r.NextDouble();
    	if(r<qk[0])              <---one error here
    	{
    		atemp[i]=a[i];
    		btemp[i]=b[i];
    	}
    	else
    	{
    		int j=1;
    		while((j<10)&&(qk[j+1]<Math.Round(r,6)))   <---- here too  
    		       j++;
                                             .
                                             .
                                             .
    it is why I want to change it to double

    thank you

  3. #3
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,399
    The NextDouble() function returns the double. Try:
    Code:
    R = r.NextDouble();
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  4. #4
    Registered User
    Join Date
    Nov 2003
    Posts
    177
    thank you .

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Storing int and double type values under one variable name
    By Thanuja91 in forum C++ Programming
    Replies: 10
    Last Post: 10-30-2007, 04:15 AM
  2. Conversion From C++ To C
    By dicon in forum C++ Programming
    Replies: 2
    Last Post: 06-10-2007, 02:54 PM
  3. functions and passing data
    By redmondtab in forum C Programming
    Replies: 41
    Last Post: 09-21-2006, 12:04 PM
  4. Unknown Math Issues.
    By Sir Andus in forum C++ Programming
    Replies: 1
    Last Post: 03-06-2006, 05:54 PM
  5. Help with multi function progam
    By WackoWolf in forum C Programming
    Replies: 22
    Last Post: 10-13-2005, 02:56 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21