Jump to content

Hey. I need to randomly pick byte values that are either 1, 2, 4, 8, or 16. How would I do this?

 

I currently have a byte assigned to no value but I want a random number generator to pick from those numbers. How would I do that?

 

Thanks. 

CPU: Intel Core i7 8700  

GPU: Gigabyte GeForce GTX 1070

MOBO: ASUS Z370-F STRIX  

RAM: 16GB Corsair Vengeance DDR4 2133MHz

Link to comment
https://linustechtips.com/topic/931351-random-bytes-in-c/
Share on other sites

Link to post
Share on other sites

1 minute ago, gabrielcarvfer said:

Get a random number from 0 to 4, shift one to the left (at least in C/C++, 1 << number, a.k.a powers of two). 


 

Ok! Thanks

CPU: Intel Core i7 8700  

GPU: Gigabyte GeForce GTX 1070

MOBO: ASUS Z370-F STRIX  

RAM: 16GB Corsair Vengeance DDR4 2133MHz

Link to comment
https://linustechtips.com/topic/931351-random-bytes-in-c/#findComment-11384200
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×