How to generate random numbers between 0 to 7 using a function that generates 0 to 3

This is a discussion on How to generate random numbers between 0 to 7 using a function that generates 0 to 3 within the C++ Programming forums, part of the General Programming Boards category; My line of thought is to use Left shift of bits. Maybe call the function twice. What would be the ...

  1. #1
    Registered User
    Join Date
    May 2012
    Posts
    2

    Question How to generate random numbers between 0 to 7 using a function that generates 0 to 3

    My line of thought is to use Left shift of bits. Maybe call the function twice.

    What would be the most efficient way?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,461
    Quote Originally Posted by Ben Frankliner
    My line of thought is to use Left shift of bits. Maybe call the function twice.
    I think you're headed in a right direction.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,296
    Maybe throw in an xor there too...
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function that generates random BST?
    By Makara in forum C Programming
    Replies: 6
    Last Post: 03-30-2012, 10:47 PM
  2. the algorithm used in c++ to generate random numbers
    By karim tarbali in forum C++ Programming
    Replies: 7
    Last Post: 02-17-2012, 07:01 AM
  3. Replies: 4
    Last Post: 01-25-2012, 06:24 PM
  4. How to generate random numbers the same everytime
    By lehe in forum C++ Programming
    Replies: 11
    Last Post: 04-09-2009, 06:00 PM
  5. How to generate random numbers between 65 and 75
    By chottachatri in forum C Programming
    Replies: 19
    Last Post: 03-02-2008, 05:24 PM

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