How to implement time filter to show random post 1 month for one category and 3 months for other categories

You cannot declare multiple functions with same name in PHP. Codex examples for this are technical demonstration, rather than ready-made usable snippet.

Give your filter functions unique names, that are not likely to clash with your own or third party code.