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. PseudoRandom functions in C++

PseudoRandom functions in C++

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestionlounge
6 Posts 5 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.
  • B Offline
    B Offline
    bigdenny200
    wrote on last edited by
    #1

    Hey all, I want to use pseudo random functions in C++, such that they take input parameters, and based on this input give output. i.e. function(param1, param2). My problem is that what I find on the internet are just simple random number generators based on seeds, which is not what I want. Does anyone know, if there is any class that I could use for above-stated purposes. ? Thanks

    J N C 3 Replies Last reply
    0
    • B bigdenny200

      Hey all, I want to use pseudo random functions in C++, such that they take input parameters, and based on this input give output. i.e. function(param1, param2). My problem is that what I find on the internet are just simple random number generators based on seeds, which is not what I want. Does anyone know, if there is any class that I could use for above-stated purposes. ? Thanks

      J Offline
      J Offline
      jhwurmbach
      wrote on last edited by
      #2

      boost::random[^]


      Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all.
      Douglas Adams, "Dirk Gently's Holistic Detective Agency"

      1 Reply Last reply
      0
      • B bigdenny200

        Hey all, I want to use pseudo random functions in C++, such that they take input parameters, and based on this input give output. i.e. function(param1, param2). My problem is that what I find on the internet are just simple random number generators based on seeds, which is not what I want. Does anyone know, if there is any class that I could use for above-stated purposes. ? Thanks

        N Offline
        N Offline
        Nathan Addy
        wrote on last edited by
        #3

        What exactly are you trying to do here? There isn't any reason to think that two or more seed parameters will be any better than a single well chosen seed. Since any random number generator basically produces a repeating (but repeating with a HUGE period) sequence that looks random, and since seeding the generator just tells the RNG where to begin iterating through that sequence, passing in multiple values won't get you anything better than passing in a single numerical value. Without knowing more about what your goal is, I would say to just use one parameter, or combine them into a single seed value, or something like that.

        B 1 Reply Last reply
        0
        • N Nathan Addy

          What exactly are you trying to do here? There isn't any reason to think that two or more seed parameters will be any better than a single well chosen seed. Since any random number generator basically produces a repeating (but repeating with a HUGE period) sequence that looks random, and since seeding the generator just tells the RNG where to begin iterating through that sequence, passing in multiple values won't get you anything better than passing in a single numerical value. Without knowing more about what your goal is, I would say to just use one parameter, or combine them into a single seed value, or something like that.

          B Offline
          B Offline
          bigdenny200
          wrote on last edited by
          #4

          I see what you mean Nathan. Yes, I could combine the values into one as well. What I need it for example following. I have a pseudorandom function F. And say F(x) = y. So that everytime I call the function with parameter x, it outputs y.

          N 1 Reply Last reply
          0
          • B bigdenny200

            Hey all, I want to use pseudo random functions in C++, such that they take input parameters, and based on this input give output. i.e. function(param1, param2). My problem is that what I find on the internet are just simple random number generators based on seeds, which is not what I want. Does anyone know, if there is any class that I could use for above-stated purposes. ? Thanks

            C Offline
            C Offline
            cp9876
            wrote on last edited by
            #5

            Your terminology is confusing, random is a property of a sequence not a function, so pseudo-random generators produce a pseudo-random stream of values, you can initialise this from a seed. It sounds that you are looking for a one-way or trapdoor function, where given x, the value f(x) appears random and difficult to invert to produce x. You could look at the standard hash functions (e.g. MD5), or alternatively something simple like exponentiation modulo some prime e.g. f(x) = r^x (mod p) where r is a primitive root mod p.


            Peter "Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."

            1 Reply Last reply
            0
            • B bigdenny200

              I see what you mean Nathan. Yes, I could combine the values into one as well. What I need it for example following. I have a pseudorandom function F. And say F(x) = y. So that everytime I call the function with parameter x, it outputs y.

              N Offline
              N Offline
              Nelek
              wrote on last edited by
              #6

              Then use a manually mathematic formulem as you want. You will always have the same output for the same input. I.E y = ABS( (((((3 - (x+1)) * (x-1) / 1.5) + ((2 - (x/5) + (x - 2/3))) / ((1 - x/7) + 2 * (x+1))) And if you want the result to be between 0 and 1, normalize the output or just divide y /= y+1;

              Greetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson ;)

              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