IPv4 addresses are usually assigned using the DHCP protocol. How this happens, depends on the particular DHCP server running on the router...
With DHCP, addresses are leased for a certain time period, so if a device reboots requests an address before the old lease expires, the router usually gives the same old address (based on DHCP client ID, or on the MAC address).
Some DHCP servers remember which address was issued even for a while after the lease expires, so they always give the same address to the same device.
If the device wasn't seen previously, it depends on the implementation – usually the new address is chosen randomly, but sometimes sequentially, and sometimes based on some sort of a hash on the MAC address so that the router at least tries to give the old address again.
For example, to quote the manual page
dhcpd.conf(5) of the ISC DHCP server dhcpd:
The DHCP server generates the list of available IP addresses from a
hash table. This means that the addresses are not sorted in any par‐
ticular order, and so it is not possible to predict the order in which
the DHCP server will allocate IP addresses. Users of previous versions
of the ISC DHCP server may have become accustomed to the DHCP server
allocating IP addresses in ascending order, but this is no longer pos‐
sible, and there is no way to configure this behavior with version 3 of
the ISC DHCP server.
For IPv6, there is a similar protocol DHCPv6, to which the answer above still applies.
However, many networks use a simpler "stateless autoconfiguration" protocol in which the router only broadcasts the prefix (aka network address), and devices assign their own IP addresses. The assignment is done in two ways:
With normal "Stateless Autoconfiguration" (RFC 4862), the 'host' part of IP addresses is based on the device's hardware address. For 48-bit MAC addresses, the second bit is flipped, and
ff:fe is inserted in the middle (to pad to 64 bits)
For example, prefix
2001:470:1f0b:915::/64 plus MAC address
48:5d:60:e8:65:8f results in IP address
With "Privacy Extensions" (RFC 4941), the 'host' part is chosen randomly – and a new address is added every 10 hours, too.
Note that "Privacy Extensions" are almost always used in addition to the normal "stateless" MAC-based IP address.