Hold your horses! :o)
Ok. First of all, you need to define if an animated gif is what you need. This depends on the image you have, the type of animation you want, and the place where you are going to put the animation.
I am making a semi-random list of ideas of several options you have to animate stuff... especially for a web page, (Which I am assuming you want the animation for)
1. Animated Gif
Normally it is best to use it at real scale, if the image is 400x400px display it as 400x400 px, do not scale it or blow it up to cover all background.
Use as few frames as possible, normally for a loop.
Use flat design style images, with a limited palette.
The background of the GIF should match (since the planning stage) the final background it will have.
But you have several other options:
2. Animate using JavaScript.
The main point here is your requirement "to randomly move the elements" the only way to randomly move elements is using JavaScript. There are some libraries that can help you animate stuff https://greensock.com/
It can animate exported assets from Illustrator to PNG or SVG...
But probably this is out of the realm of graphic design and more into programming... so let's forget this for now.
3. Using a specific JS
For example, if the thing you want to animate is snow... search for some codes already made you can use:
https://duckduckgo.com/?q=snow+js
4. Animating using CSS
This is in the realm of graphic web designers... But you need how to code HTML and CSS.
https://duckduckgo.com/?q=css+animations
But this will not be random at all, this will be keyframe animations.
5. Video
This will assume your "randomness" is inside the video itself... an explosion has random stuff flying around. You normally will use Mp4 video and paste it as a background using some JavaScript.
6. Looping a background
This is the approach you are describing... which is not a good idea because this needs to load the entire image each time.
You can do it using PNG sprites animation, and animating them using CSS.
https://duckduckgo.com/?q=css+sprite+animation
If you still want to go with animated gifs... you can use Blender (blender.org) which is free and assigns emission materials and turns off shadows, to have a flat look.

Normally you will have keyframe animation... or you can add particle systems to generate really random stuff... or you can use parametric animation... The possibilities are endless.