Used sys.ku$_objnumset for convenience as it already exists, but any collection type will do as long as it is in scope for SQL. Typically this means a schema-level type created using CREATE OR REPLACE TYPE x AS TABLE OF y, although in some cases a type defined in a package specification can be used (depending on Oracle version and how you feel about temporary objects appearing in your schema).
Define a table function
create or replace function get_num
( p_length in integer )
return sys.ku$_objnumset
is
l_numlist sys.ku$_objnumset := sys.ku$_objnumset();
begin
l_numlist.extend(p_length);
for i in 1..p_length loop
l_numlist(i) := i;
end loop;
return l_numlist;
end get_num;