function GroupLayers() {
    app.beginUndoGroup("Random-Select-Deselect");
    var comp = app.project.activeItem;
    if (!comp || !(comp instanceof CompItem)) { // If no comp is selected
        alert("Please select a composition");
        return;
    }
    var layers = comp.selectedLayers;
    if (layers.length == 0) { // If no layer is selected   

        for (var i = 1; i < comp.layers.length; i++) {
            var layer = comp.layers[i];
            var n = generateRandomNumber();
            if (n > 0.5) {
                layer.selected = true;
            }
        }

    }
    for (var i = 0; i < layers.length; i++) {
        var layer = layers[i];
        var n = generateRandomNumber();
        if (n > 0.75) {
            layer.selected = false
        }
    }
    app.endUndoGroup();
}
GroupLayers();