Handling Our Random Numbers
We can also work with some of the random numbers.
These random numbers are going to be the functions that we can use to help create random numbers in any program that we write.
We must note with this one though that our computer can never really be all that random or spontaneous though.
This is because all of the parts that we see are going to be based on whatever input the computer gets, and it is going to react in the manner that seems the most logical to it.
The first type of random number that we are able to work with here is going to be the function of randomSeed(number).
This one is going to start up with the generator of a random number so that we can work with that.
We first need to make sure that we feed a number all the way through it, and then it will start again at a random point, which the computer program will choose from the sequence of the pseudo-random number generator’s numerical sequence.
We can take this a bit further here and work with the function of random(OPTIONAL minimum, maximum).
This is one that is useful because it can bound together with the generation of the random number.
The maximum value is going to end up being the higher number you are going to allow here, and then the lowest is the lowest number you will allow.
If you do not go through and specify out the minimum you want to work with, then the assumption is that it will be at 0.
A Look at the Bitwise Functions
The final thing that we want to take a look at when it comes to the functions of the Arduino API is the bitwise functions.
These are a specific type of function that is going to make it easier to work with the bytes and the bits of all your codes.
These are going to be considered the smallest parts of data that the computer can actually work with.
There are arguments that there are some smaller data types, but for our practical purposes, this is where we need to go with the smallest parts.
Some of the different bitwise functions that we are able to use with Arduino include:
- bit(bitNum):
This one is going to provide us with the value of a given bit.
- bitClear(variable, bit):
This one is going to be how we set the given bit of a specified numerical variable to 0.
- bitRead(variable, bit):
This is going to give back the bit of a specified numeric variable.
- bitSet(variable, bit):
This is going to set a given variable’s bit like the position denoted by bit to 1.
- bitWrite9(variable, bit, 0 or 1):
This one will set the bit at the given position inside of the variable to either be at 0 or 1, depending on what you set in the code.
- highByte(value):
This one is going o return to us the highest byte of a given value that we have.
- lowByte(value):
This one is going to be the opposite of before, and it is going to return the lowest byte of the value that you choose to look at.
As we can already see here, there are a ton of different functions that we are able to use when it comes to the API that is part of Arduino.
Learning what all of these can do for us and exploring them in more detail is going to make a huge difference in what we are able to do with these as well.
As you get more familiar with the Arduino controller and all of the neat things that it is able to do, you will quickly see why this is a great option to work with, and you will be able to see these functions doing some actual work in the process as well.