Yes, slots and weapon stats are both completely random, although they weapon quality is heavily influenced by the Construction (CST) level of the constructor building your item.
The following information regarding slots is detailed on the Tech Haven wiki;
There are 2 variables in the formula that determines the amount of slots: the quality of the built item and a random number (0-199). Although quality of constructed items has a cap, the quality used by the formula is the theoretical quality, so having just enough CST to reach the build cap for the desired item is far from being optimal. In fact, if the quality is below a certain level, it is not possible to get 5 or even 4 slots. This quality is based on the TL of the constructed item DEX, INT and your CST skill.
So having a high build quality opens up the possibilities to get up to 5 slots. To get the slots, a random number is rolled. If that random number is above a certain number (derived from fixed factors and also the quality), you get 0 slots. For 1 slot, the random number has to be lower than the calculated number above. For 2 slots, it has to be below another number that's lower than that required for 1 slot. Same thing for 3, 4, 5 slots, the random number the game rolls has to be lower and lower. That's why builds with low quality can never get 5 slots, the required number would have to be negative (which it can't be).
As the quality factors into the formula determining the breakpoints for x slots, a high quality means a bigger range of random numbers will be able to get you slots. In other words, it increases your chances to get slots.
Rare weapons are a special case though. In addition to the formula described above, there is another roll for 0, 1 or 2 additional slots (33.33% chance to get either). That's why rare weapons generally have more slots than non-rares.
It is possible to guarantee a minimum number of slots by combining a slot enhancer with the materials required to build the weapon during the construction process. There are three different levels of slot enhancer, and all three of them can only be obtained by killing enemies in the DoY Tunnels, or by trading for them. For rare weapons you will be looking for 'illegal slot enhancers', which are the highest level of slot enhancer, the two lower level ones cannot be used when creating rare weapons.