Knowing the gender before translating into french
When translating from english (for instance), there is no rule to know if the word will be feminine or masculine in french.
You have to know it by heart.
Sorry.
Knowing gender from the word itself
If you are reading a french word, you may have clues on the ending of the word, which you may see on the linked question
Origins
It may come from Latin or Roman. You may see the same behavior with Italian, German, Spanish... This is not specific to French.
You may see an article on it here on chapter Les systèmes de genres