There is way too much missing to provide a complete answer but I will try and add some guidance from experience. You state that you want random groups of notes to be "meaningful" but can you define a criterion for meaningful (or is that what you want from us). What makes music meaningful in many cultures is rhythm not melody (though both are important).
From a melodic perspective we tend to like simple melodic phrases that move around within a key signature, e.g. on the major scale (or relative minor). There is a simpler unit of musical expression called a tetrachord (Do, Re, Mi, Fa). The major scale is just 2 tetra chords separated by a step. The reason I feel that this is important is that there is "repetition" built into the ascending scale, and repetition is what many people crave (whether they know it or not). So even simple melodic phrases (say three or four notes long) tend to (1) have a repeated or well defined rhythm or pulse (2) either have or hint at melodic repetition and (3) tend to stay within a key. Of course there are exceptions to every rule. And you cannot really repeat yourself with 3 notes unless it's the same note 3 time. But, longer phrases like the ones you are trying to make are usually built from simpler 3 and 4 note phrases repeated at the same or different places within the key. So a better algorithm might be to randomly move the phrase (Do, Mi, Re) around varying the starting pitch (with or without constraints to stay in key). Perhaps a library of small phrases.
I would ask why you want to do this at random. Why? What are you testing? If you can share this it might help. Unless it's proprietary (I'd understand). Music is filled with patterns and IMO there is nothing random about it. If you are trying to see what it takes for subjects to tell the difference between human generated music and computer generated music that won't take much. If you are trying to create AI that mimics human creativity that might take more. We are pattern recognition machines and we crave pattern. If you wan to generate short melodies to make life easy you will need more than a random tone generator. You will need some constraints that create rhythm and melodic structure consistent with western tastes. That would essentially mean coding up a text on music theory.
A couple other constraints might help. One is that moving small patterns around we usually come back where we started, in other words we cycle rather that just move endlessly in one direction. A small chunk of music light have a scale going up but will eventually come back around. This is critical to creating the feeling of completeness. Phases can begin and end on different notes but usually notes that are part of the Tonic chord of the key (Do, Mi, Sol). So this is a second thing to consider. Third, you didn't state how many octaves you were restricted to (unless I missed it). For a 16 note phrase it is possible, but highly unlikely, to generate a 2 octave scale. This is not very musical even though it is a musical element. You need to either restrict your "random" choices to be within an octave or octave and a 5th or require that they turn around somewhere.
There are a lot of degrees of freedom to play with. It is possible to encapsulate some of our decision making process in the constraints and try randomizing the rest but you have a lot to think about. And there is also the possibility of chromaticism. Are you trying to emulate real musical phrases at random?