Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Blum Blum Shub

Blum Blum Shub

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
22 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member_14956475
    wrote on last edited by
    #1

    Hi everyone . I am a newbie in programming , so i would be very grateful if you could help me . I have to implement the Blum Blum Shub in C or C++ using the stdlib.h and time.h libraries . Can anyone help me with this ? Thanks :)

    V J L Z D 6 Replies Last reply
    0
    • M Member_14956475

      Hi everyone . I am a newbie in programming , so i would be very grateful if you could help me . I have to implement the Blum Blum Shub in C or C++ using the stdlib.h and time.h libraries . Can anyone help me with this ? Thanks :)

      V Offline
      V Offline
      Victor Nijegorodov
      wrote on last edited by
      #2

      And what exactly is your problem?

      M 1 Reply Last reply
      0
      • V Victor Nijegorodov

        And what exactly is your problem?

        M Offline
        M Offline
        Member_14956475
        wrote on last edited by
        #3

        I have to create a random number generator Blum Blum Shub in C or C++ ,using libraries stlib.h and time.h

        V 1 Reply Last reply
        0
        • M Member_14956475

          Hi everyone . I am a newbie in programming , so i would be very grateful if you could help me . I have to implement the Blum Blum Shub in C or C++ using the stdlib.h and time.h libraries . Can anyone help me with this ? Thanks :)

          J Offline
          J Offline
          jeron1
          wrote on last edited by
          #4

          Maybe take a look at this article. CBBS: A Pseudo Random Number Generator[^]

          "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

          M 1 Reply Last reply
          0
          • J jeron1

            Maybe take a look at this article. CBBS: A Pseudo Random Number Generator[^]

            "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

            M Offline
            M Offline
            Member_14956475
            wrote on last edited by
            #5

            I already took a look at him but i need not a so complex code , only a simple version with these two libraries that i mentioned.

            1 Reply Last reply
            0
            • M Member_14956475

              Hi everyone . I am a newbie in programming , so i would be very grateful if you could help me . I have to implement the Blum Blum Shub in C or C++ using the stdlib.h and time.h libraries . Can anyone help me with this ? Thanks :)

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              c random - Google Search[^] and Blum Blum Shub - Wikipedia[^]

              M 1 Reply Last reply
              0
              • L Lost User

                c random - Google Search[^] and Blum Blum Shub - Wikipedia[^]

                M Offline
                M Offline
                Member_14956475
                wrote on last edited by
                #7

                And time.h how to use in it?

                L 1 Reply Last reply
                0
                • M Member_14956475

                  I have to create a random number generator Blum Blum Shub in C or C++ ,using libraries stlib.h and time.h

                  V Offline
                  V Offline
                  Victor Nijegorodov
                  wrote on last edited by
                  #8

                  Then do it!

                  1 Reply Last reply
                  0
                  • M Member_14956475

                    And time.h how to use in it?

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #9

                    No idea, because we do not have the instructions that your teacher gave you. If you read the documentation for the random and time functions (time, _time32, _time64 | Microsoft Docs[^]) you should be able to decide how they can help you.

                    M 1 Reply Last reply
                    0
                    • L Lost User

                      No idea, because we do not have the instructions that your teacher gave you. If you read the documentation for the random and time functions (time, _time32, _time64 | Microsoft Docs[^]) you should be able to decide how they can help you.

                      M Offline
                      M Offline
                      Member_14956475
                      wrote on last edited by
                      #10

                      Here's the full indications that i have : Purpose: to develop a function that generates random numbers from a given range. Elaboration of the module for generating random numbers Resources : C or C++ compiler stdlib.h and time.h libraries Algorithm Blum Blum Shub Hope it helps in any kind

                      L 1 Reply Last reply
                      0
                      • M Member_14956475

                        Here's the full indications that i have : Purpose: to develop a function that generates random numbers from a given range. Elaboration of the module for generating random numbers Resources : C or C++ compiler stdlib.h and time.h libraries Algorithm Blum Blum Shub Hope it helps in any kind

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #11

                        So, you have all the information you need, time to get started. If you were under the mistaken impression that someone here was going to do your work for you ...

                        1 Reply Last reply
                        0
                        • M Member_14956475

                          Hi everyone . I am a newbie in programming , so i would be very grateful if you could help me . I have to implement the Blum Blum Shub in C or C++ using the stdlib.h and time.h libraries . Can anyone help me with this ? Thanks :)

                          Z Offline
                          Z Offline
                          ZurdoDev
                          wrote on last edited by
                          #12

                          You are not asking a specific question. You are essentially asking someone to do all the work for you, which will not happen. Get started on it and if you get stuck on something specific then come back and show where you are stuck and someone will be glad to help.

                          Social Media - A platform that makes it easier for the crazies to find each other. Everyone is born right handed. Only the strongest overcome it. Fight for left-handed rights and hand equality.

                          1 Reply Last reply
                          0
                          • M Member_14956475

                            Hi everyone . I am a newbie in programming , so i would be very grateful if you could help me . I have to implement the Blum Blum Shub in C or C++ using the stdlib.h and time.h libraries . Can anyone help me with this ? Thanks :)

                            D Offline
                            D Offline
                            David Crow
                            wrote on last edited by
                            #13

                            Member 14956475 wrote:

                            I have to implement the Blum Blum Shub in C or C++...

                            More importantly, can you do it with pencil and paper? If the answer is no, then: 1) you are going to be hard pressed to implement it in code, and 2) you should work on it until you can produce results on paper. Don't let computer code take the place of the basic understanding of algorithms.

                            "One man's wage rise is another man's price increase." - Harold Wilson

                            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                            "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                            M 1 Reply Last reply
                            0
                            • D David Crow

                              Member 14956475 wrote:

                              I have to implement the Blum Blum Shub in C or C++...

                              More importantly, can you do it with pencil and paper? If the answer is no, then: 1) you are going to be hard pressed to implement it in code, and 2) you should work on it until you can produce results on paper. Don't let computer code take the place of the basic understanding of algorithms.

                              "One man's wage rise is another man's price increase." - Harold Wilson

                              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                              "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                              M Offline
                              M Offline
                              Member_14956475
                              wrote on last edited by
                              #14

                              Okay , this is the code that i managed to do :

                              #include
                              #include
                              #include
                              /*BLUM BLUM SHUB*/

                              int main()
                              {

                              const int p = 30000000091;
                              const int q = 40000000003;
                              int N ;
                              scanf("%i", &N);
                              const unsigned long long int s = 1200000003730000000273;
                              unsigned int i,M,x[N];
                              time_t t;
                              srand((unsigned) time(&t));

                              M=p*q;

                              i=0;
                              x[0]=s;
                              for(i=1;i<=N;i++){
                              x[i]=(x[i-1]*x[i-1])%M;
                              }
                              for(i=1;i<=N;i++){
                              printf(" x[%d] = %d\n",i,x[i]);
                              }

                              system("PAUSE");
                              return 0;
                              }

                              I have some issues with it , first it's that i need to add from console the biggest number D and i dont know how to put it in as now it's generating numbers without upper limit . Also can anyone tell me how to fix the code as it generates the same numbers at some intervals , if you have other remarks on how to make it better tell me please . Thanks:)

                              Richard Andrew x64R D 2 Replies Last reply
                              0
                              • M Member_14956475

                                Okay , this is the code that i managed to do :

                                #include
                                #include
                                #include
                                /*BLUM BLUM SHUB*/

                                int main()
                                {

                                const int p = 30000000091;
                                const int q = 40000000003;
                                int N ;
                                scanf("%i", &N);
                                const unsigned long long int s = 1200000003730000000273;
                                unsigned int i,M,x[N];
                                time_t t;
                                srand((unsigned) time(&t));

                                M=p*q;

                                i=0;
                                x[0]=s;
                                for(i=1;i<=N;i++){
                                x[i]=(x[i-1]*x[i-1])%M;
                                }
                                for(i=1;i<=N;i++){
                                printf(" x[%d] = %d\n",i,x[i]);
                                }

                                system("PAUSE");
                                return 0;
                                }

                                I have some issues with it , first it's that i need to add from console the biggest number D and i dont know how to put it in as now it's generating numbers without upper limit . Also can anyone tell me how to fix the code as it generates the same numbers at some intervals , if you have other remarks on how to make it better tell me please . Thanks:)

                                Richard Andrew x64R Offline
                                Richard Andrew x64R Offline
                                Richard Andrew x64
                                wrote on last edited by
                                #15

                                I found at least one issue with the code: You're using the variable N before you initialize it with a value. This is a no no.

                                The difficult we do right away... ...the impossible takes slightly longer.

                                1 Reply Last reply
                                0
                                • M Member_14956475

                                  Okay , this is the code that i managed to do :

                                  #include
                                  #include
                                  #include
                                  /*BLUM BLUM SHUB*/

                                  int main()
                                  {

                                  const int p = 30000000091;
                                  const int q = 40000000003;
                                  int N ;
                                  scanf("%i", &N);
                                  const unsigned long long int s = 1200000003730000000273;
                                  unsigned int i,M,x[N];
                                  time_t t;
                                  srand((unsigned) time(&t));

                                  M=p*q;

                                  i=0;
                                  x[0]=s;
                                  for(i=1;i<=N;i++){
                                  x[i]=(x[i-1]*x[i-1])%M;
                                  }
                                  for(i=1;i<=N;i++){
                                  printf(" x[%d] = %d\n",i,x[i]);
                                  }

                                  system("PAUSE");
                                  return 0;
                                  }

                                  I have some issues with it , first it's that i need to add from console the biggest number D and i dont know how to put it in as now it's generating numbers without upper limit . Also can anyone tell me how to fix the code as it generates the same numbers at some intervals , if you have other remarks on how to make it better tell me please . Thanks:)

                                  D Offline
                                  D Offline
                                  David Crow
                                  wrote on last edited by
                                  #16

                                  Member 14956475 wrote:

                                  ...i need to add from console the biggest number D and i dont know how to put it in as now it's generating numbers without upper limit .

                                  Change your main() signature to:

                                  void main( int argc, char *argv[] )

                                  Then access argv[1] to get D as a command line argument. Also, your two for() loops are accessing beyond the end of the x array. In C, arrays start at 0.

                                  "One man's wage rise is another man's price increase." - Harold Wilson

                                  "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                                  "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                                  M 1 Reply Last reply
                                  0
                                  • D David Crow

                                    Member 14956475 wrote:

                                    ...i need to add from console the biggest number D and i dont know how to put it in as now it's generating numbers without upper limit .

                                    Change your main() signature to:

                                    void main( int argc, char *argv[] )

                                    Then access argv[1] to get D as a command line argument. Also, your two for() loops are accessing beyond the end of the x array. In C, arrays start at 0.

                                    "One man's wage rise is another man's price increase." - Harold Wilson

                                    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                                    "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                                    M Offline
                                    M Offline
                                    Member_14956475
                                    wrote on last edited by
                                    #17

                                    I've replaced main() with

                                    void main( int argc, char *argv[] )

                                    , but how can i acces argv[1] to get D as a command line argument?

                                    D 1 Reply Last reply
                                    0
                                    • M Member_14956475

                                      I've replaced main() with

                                      void main( int argc, char *argv[] )

                                      , but how can i acces argv[1] to get D as a command line argument?

                                      D Offline
                                      D Offline
                                      David Crow
                                      wrote on last edited by
                                      #18

                                      Member 14956475 wrote:

                                      ...but how can i acces argv[1] to get D as a command line argument?

                                      The same way you would access parameters from within any other function. main() is no different. See here for more.

                                      Member 14956475 wrote:

                                      ...is it possible to use srand command?

                                      Your code is already doing that. However, the way in which you are using it is meaningless since you are also not calling rand(). rand() by itself will always generate the same sequence of numbers. srand() will "seed" the number generation process to start at a different spot.

                                      "One man's wage rise is another man's price increase." - Harold Wilson

                                      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                                      "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                                      M 1 Reply Last reply
                                      0
                                      • D David Crow

                                        Member 14956475 wrote:

                                        ...but how can i acces argv[1] to get D as a command line argument?

                                        The same way you would access parameters from within any other function. main() is no different. See here for more.

                                        Member 14956475 wrote:

                                        ...is it possible to use srand command?

                                        Your code is already doing that. However, the way in which you are using it is meaningless since you are also not calling rand(). rand() by itself will always generate the same sequence of numbers. srand() will "seed" the number generation process to start at a different spot.

                                        "One man's wage rise is another man's price increase." - Harold Wilson

                                        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                                        "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                                        M Offline
                                        M Offline
                                        Member_14956475
                                        wrote on last edited by
                                        #19

                                        #include #include #include /*BLUM BLUM SHUB*/ int main () { const int p = 347; const int q = 351; const unsigned long long int s = 12373273; int N ; printf("enter the number:"); scanf("%i", &N); unsigned int i,M,x[N]; srand(time(NULL)); M=p*q; i=0; x[0]=s; for(i=1;i<=N;i++){ x[i]=rand()*(x[i-1]*x[i-1])%M; } for(i=1;i<=N;i++){ printf("%d\t",x[i]); } system("PAUSE"); return 0; } I added srand and rand is it okay working now ?

                                        D 1 Reply Last reply
                                        0
                                        • M Member_14956475

                                          #include #include #include /*BLUM BLUM SHUB*/ int main () { const int p = 347; const int q = 351; const unsigned long long int s = 12373273; int N ; printf("enter the number:"); scanf("%i", &N); unsigned int i,M,x[N]; srand(time(NULL)); M=p*q; i=0; x[0]=s; for(i=1;i<=N;i++){ x[i]=rand()*(x[i-1]*x[i-1])%M; } for(i=1;i<=N;i++){ printf("%d\t",x[i]); } system("PAUSE"); return 0; } I added srand and rand is it okay working now ?

                                          D Offline
                                          D Offline
                                          David Crow
                                          wrote on last edited by
                                          #20

                                          Member 14956475 wrote:

                                          is it okay working now ?

                                          Only you can determine that.

                                          "One man's wage rise is another man's price increase." - Harold Wilson

                                          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                                          "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups