How to generate random numbers of the same at each time of execution of thm

dear friends
i am facing a problem that the random numbers generated at time of each exectuion of the program are not the same, i want to generate the same random numbers every time time i run the program. i need your help. i am giving the code in c++ if anybody can help in providing the solution so that i get the same random numbers at every run of the program. waiting for your help
wit regards
jaya shankar
#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
class density
int s[150][150],parent[150][150],i,j,l,n,loop;
public:
void bd(void);
void css(void);
void density :: bd(void)
cout<<"ENTER THE POPULATION SIZE = ";
cin>>n;
cout<<"\nENTER THE NO.OF LOOPS = ";
cin>>loop;
for(i=0;i<n;i++)
for(j=0;j<80;j++)
s[j]=rand()%2;
cout<<"s:"<<s[j];
void density :: css(void)
int a,b;
float c;
for(i=0;i<n;i=i+2)
b=rand()%100;
cout<<"random b="<<b;
main()
density d;
d.bd();
d.css();

Do not randomize the random number interface when you start your application. When the random number interface is not randomized when starting you get the same sequence of numbers each and every time you use it.

Similar Messages

  • How to generate random numbers from 1 to 5

    How to generate random numbers from 1 to 5   
    -1110340081
    Solved!
    Go to Solution.

    (You should not mark a post as solution unless it actually contains a solution to the original problem)
    Do you want to share your code? Did you test to make sure that all numbers equally probable?
    LabVIEW Champion . Do more with less code and in less time .

  • How to generate random numbers in a range using random class?

    I know how to use Math.random for this, but how would I generate random numbers using the random class?
    Say I want a number between 40 and 50, inclusive--how would I do this?
    What i have in mind is:
    int randomNumber = random.nextInt(max) + min;
    where max is 50 and min is 40. Is this correct?

    Fredddir_Java wrote:
    I know how to use Math.random for this, but how would I generate random numbers using the random class?
    Say I want a number between 40 and 50, inclusive--how would I do this?
    What i have in mind is:
    int randomNumber = random.nextInt(max) + min;
    where max is 50 and min is 40. Is this correct?What happened when you generated a couple hundred numbers that way? Did you get all the ints in the range you wanted?

  • 10.6.8 update won't install gets half way through then just freezes spinning beach ball for 4 hours any ideas y. Tried and restarted 3 times already does the same thing each time have to hold down the power button to restart

    10.6.8 update won't install gets half way through then just freezes spinning beach ball for 4 hours any ideas y. Tried and restarted 3 times already does the same thing each time have to hold down the power button to restart. Anyone can help

    Ok will check, as of right now I have 82.57gb free, that's plenty of space will check the disk though using disk utility. Also I am now downloading the update from the apple website instead of going through software update

  • My CS6 program that has never had a problem before, is not telling me that there is an error and that it "unexpectedly quit" when I simply try to launch the program.  I have restarted my computer several times.  It does the same thing each time.  So then

    My CS6 program that has never had a problem before, is not telling me that there is an error and that it "unexpectedly quit" when I simply try to launch the program.  I have restarted my computer several times.  It does the same thing each time.  So then I tried uninstalling the program and re-installing.  It said that it could not install due to an error.  So I STILL can't launch my program.  I don't know what to do.  Any help would be appreciated.  I have to edit photos for a photoshoot and return them tomorrow. :/

    Reset Photoshop's Preferences?
    Your Photoehop preferences will survive un-installing and re-installing Photoshop......

  • I am having trouble importing photos, gets stuck on the same photo each time?!?

    I am having trouble importing almost 3000 pics from my phone to my computer. Start up disk should be fine, cleaned it up before I began.  Import gets stuck on the same photo each time I try the import.  I have had to force quit a few times, and it can't seem to get past that same picture near the end.  Please help?!? It never gives me an error, it just keeps spinning and nothing is importing.

    Launch the Console application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad. Click Utilities, then Console in the icon grid.
    The title of the Console window should be All Messages. If it isn't, select
              SYSTEM LOG QUERIES ▹ All Messages
    from the log list on the left. If you don't see that list, select
              View ▹ Show Log List
    from the menu bar at the top of the screen.Click the Clear Display icon in the toolbar. Then take one of the actions that you're having trouble with. Select any messages that appear in the Console window. Copy them to the Clipboard by pressing the key combination command-C. Paste into a reply to this message by pressing command-V.
    The log contains a vast amount of information, almost all of which is irrelevant to solving any particular problem. When posting a log extract, be selective. A few dozen lines are almost always more than enough.
    Please don't indiscriminately dump thousands of lines from the log into this discussion.
    Please don't post screenshots of log messages—post the text.
    Some private information, such as your name, may appear in the log. Anonymize before posting.

  • Screen Saver doesn't allow SOURCE SELECTION but automatically begins to download unknown files. I have to force quit, but it does the same thing each time I try to select a source.

    Screen Saver doesn't allow SOURCE SELECTION but automatically begins to download unknown files. I have to force quit, but it does the same thing each time I try to select a source.

    Do you realize that you're talking to yourself?
    iMac refurb (27-inch Mid 2011), OS X Mavericks (10.9.4), SL & ML, G4 450 MP w/Leopard, 9.2.2

  • How to generate random numbers that doesnt contain characters?

    How do we generate random numbers in ESB ROuting Service/ XSL transformation that does not contain characters. I have been using "orcl:generate-guid()" , but it contains some characters, so, I substring it to get only numbers. I dont want to take this risk and in future, my substring itself may contain characters.
    Has anybdy tried this before?
    Thanks,

    If the goal is to have a pseudo random number then consider using the translate function to replace the occurances of the A - E characters with another digit. For example:
    translate(orcl:generate-guid(),'0123456789ABCDEF','0123456789123456')
    This will produce a 1 for A, 2 for B, etc. While not a valid hex to decimal conversion of the GUID value, it does get around the hex issue and might be sufficient for your purposes.
    I would perform a large sample test to see just how unique the values end up being.
    As for why hex is used, well GUID's are most commonly written in text as a sequence of hexadecimal digits such as: 3F2504E0-4F89-11D3-9A0C-0305E82C3301. i.e. 128 bits represented in 32 characters formatted into 5 sections.
    Hope this helps,
    Peter

  • How t generate random numbers at everytime of exceutuion of the program

    dear friends
    i am facing a problem that the random numbers generated at time of each exectuion of the program are not the same, i want to generate the same random numbers every time time i run the program. i need your help. i am giving the code in c++ if anybody can help in providing the solution so that i get the same random numbers at every run of the program. waiting for your help
    wit regards
    jaya shankar
    #include<iostream.h>
    #include<stdio.h>
    #include<stdlib.h>
    #include<time.h>
    #include<math.h>
    class density
    int s[150][150],parent[150][150],i,j,l,n,loop;
    public:
    void bd(void);
    void css(void);
    void density :: bd(void)
    cout<<"ENTER THE POPULATION SIZE = ";
    cin>>n;
    cout<<"\nENTER THE NO.OF LOOPS = ";
    cin>>loop;
    for(i=0;i<n;i++)
    for(j=0;j<80;j++)
    s[j]=rand()%2;
    cout<<"s:"<<s[j];
    void density :: css(void)
    int a,b;
    float c;
    for(i=0;i<n;i=i+2)
    b=rand()%100;
    cout<<"random b="<<b;
    main()
    density d;
    d.bd();
    d.css();

    This will help you I think.
    import java.io.*;
    import java.util.*;
    public class RandomTest
         public static void main( String arg[]) throws Exception
              Random number = new Random(100);
              for( int i = 0 ; i < 15; i++){
                   System.out.println( number.nextInt( 100 )) ;

  • How to generate random numbers in a range?

    Hello. i am having trouble finding out how to generate a random number in a certain range. For example i have an array of 100 elements and i want to access one of the elements between 50 and 60, however i cannot find how to generate a random number between these two values.
    Thanks in advance

    java.util.Random.nextInt(int)
    Note that you can get a number between 0 and (max -
    min), exclusive. Then add min, and you've got your
    number.Obviously you didn't read this. It says to get a number between 0 and (max - min) which is actually what you did. But after that you need to add min. The first step would get a number in between 0 and 5. When you add 20 you'd get a number between 0+20=20 and 5+20=25.

  • How do you sort numbers in the same field in excel 2010 the same for access 2010

    Hi,
    Is there a way to sort data horizontally in the same field in excel and for access, or is there an addin that can do this
    or  function code
    field data    6-4-25-23-11-45
    sort order 4-6-11-23-25-45
    Regards,
    Rudolf
    rudolfelizabeth

    sort data horizontally in the same field in excel
    Does "in the same field" means that the string "6-4-25-23-11-45" is located in one cell?
    In that case you have to use an UDF. Paste this code into a regular module:
    Function SortNumbersPrim(ByVal What As String, Optional ByVal Delimiter) As Variant
      Dim Arr, Temp
      Dim i As Long, j As Long
      Arr = Split(What, Delimiter)
      For i = LBound(Arr) + 1 To UBound(Arr)
        Temp = Val(Arr(i))
        For j = i - 1 To LBound(Arr) Step -1
          If Val(Arr(j)) <= Temp Then Exit For
          Arr(j + 1) = Arr(j)
        Next
        Arr(j + 1) = Temp
      Next
      SortNumbersPrim = Join(Arr, Delimiter)
    End Function
    Then use a formula like this:
    =SortNumbersPrim(A1,"-")
    Andreas.

  • I had to reset my computer and redownload Itunes. My iphone 5 will not connect to the new itunes i have trusted the computer but it keeps bringing up the same question each time i reconnect to the computer. How can i get my phone to connect to itunes

    I had to reset my computer because of a virus i had. When i re installed itunes my music was gone. I went to plug in my Iphone 5 and know my phone does not recognize the computer. I also have hit the trust button on my iphone but have to continue trusting the computer each time it gets plugged in. Still the phone wont connect to itunes at all to view what is on the phone. How do i fix this connection problem?

    Hey ebe301,
    Sorry to hear about your troubles with your PC. If you are not seeing your iPhone on your computer, then take a look at the link below to walk you through getting that working again. It will have you verify that drivers are installed and working as well as any third party software that may be causing conflicts. 
    iPhone, iPad, or iPod not recognized in iTunes for Windows
    https://support.apple.com/en-us/HT204095
    Take care,
    -Norm G.  

  • My BlackBerry gets stuck at the same point each time on the "restart" screen. HELP!?

    After updating some apps, I was told to reboot my phone. I did this and realised it had been stuck on the same part of the "loading bar" for quite a while. I thought this was just a glich and took the battery out to try again and once again it got stuck on the SAME part of the bar. Since then I have taken the battery out many more times and I don't know what to do! Please help, I can't go without my phone!

    Go to Main Menu->Options->Applications and check whether the apps that you've updated are displayed or not. If yes, try to delete the applications and make a fresh install of the apps.
    Daya

  • How to generate random numbers with a known distribution of f(X)=(8X^2 + 1)*Exp( -X^2 )

    Dear All,
    I need to simulate a random number generator which can generate numbers X with the probability distribution of 
     f (X) = ( 8X^2 + 1)*Exp ( -X^2 ).
    This distribution is not a common distribution.
    I have searched a lot, but I still do not know how to realize it.
    Any help on this topic would be highly appreciated.

    Make a lookup table of the integral of your function (normalized to 1)
    Use the rectangle random generator and pipe that value through the lookup table, scale it ... voila.
    Greetings from Germany
    Henrik
    LV since v3.1
    “ground” is a convenient fantasy
    '˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'

  • How to generate random numbers with a known distributi​on f(X)=(8X^2 + 1)*Exp( -X^2 ).

    I need to simulate a random number generator which can generate numbers X with the probability distribution of 
     f (X) = ( 8X^2 + 1)*Exp ( -X^2 ).
    This distribution is not a common distribution.
    I have searched a lot, but I still do not know how to realize it.
    Thanks a lot!
    Solved!
    Go to Solution.

    Don't forget to index back into the original X array for correctly scaled data. Here's a simple example (LV 8.0):
    Seems to work just fine.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    DistributionSimulation.png ‏25 KB
    DistributionSim4.vi ‏44 KB

Maybe you are looking for

  • Missing drivers after upgrade to Win 7 in HP pavilion dv9500

     I upgraded my laptop to Windows 7 32 bit and everything works except from 2 base system devices listed in device manager that need work. What should I do?

  • Error FF 711 raised during posting of items in FI-AP

    Hello Friends, we are getting error message FF 711 when trying to post from the ICM module into FI-AP using the BAPI_ACC_INVOICE_POST funcation Module. We have both service tax and withholding tax calculation switched on and everythings seems to work

  • Wmv player on solaris 10 x86

    hi ppl..i ve recently installed solaris 10 x86...and i think that if u can t see porn videos on computer then its wastage of resources...most of the vids on net available r of wmv format...so my q is that where can i get wmv player for solaris 10 x86

  • Journal Voucher SDK bug?

    Hi guys, I have created an add-on that reads data from a text file and creates a journal voucher. The add-on works well, but I have noticed a bug when I create a journal voucher with more than one currency. The bug does not seem to be from my code. I

  • Acrobat 8.1 update

    Since the 8.1 update, I have been unable to view .pdf files in my folders. Is there a setting so I don't have to actually open the file but can preview it? I've checked all settings but haven't seen what I'm looking for.