i'm curious about this aspect... but the number of transactions per block is based on what? it's random?
Keep in mind that the below is only a reflection of the default settings from bitcoin core. Miners can write their own versions with different rules.
No its not random. Firstly the mining node must be aware of transactions otherwise the block will be "empty". That is only include the coinbase TX. The transactions get sort by priority and fee. They include "blockprioritysize" (default is 50000) byte worth of transactions into the block that have a high priortiy but no (or low) fee. They further fill the block up to "blockmaxsize" (default is 750000) bytes worth of transactions. Its also possible to set "blockminsize" (default is 0) to make sure the block has at least a certain size. If not enough TX are present blockminsize will not keep you from hashing.
Its here[1] in the source and here[2] are the default values for the settings.
[1] https://github.com/bitcoin/bitcoin/blob/master/src/miner.cpp
[2] https://en.bitcoin.it/wiki/Running_Bitcoin