# `AUTO_RANDOM` Attribute

__*AUTO_RANDOM*__
__*PK_AUTO_RANDOM_BITS*__

+ **`AUTO_RANDOM`**: is a field property that is used to automatically and randomly populate default column values to resolve hot issues
  + Only **`BIGINT`** data types are supported
  + It's a random generator based on shards
  + **`LAST_INSERT_ID()`**: Similar to **`AUTO_INCREMENT`**, it retrieves the value used for the last insert
+ e.g: **`CREATE TABLE test.ar (id BIGINT PRIMARY KEY AUTO_RANDOM, name BOOLEAN)`** 
```
tidb> SELECT ~!@TIDB_ROW_ID_SHARDING_INFO@!~
   -> FROM ~!@information_schema.tables@!~
   -> WHERE table_name='ar' AND table_schema='test';
+---------------------------+
| TIDB_ROW_ID_SHARDING_INFO |
+---------------------------+
| PK_AUTO_RANDOM_BITS=5     |
+---------------------------+
1 row in set (0.01 sec)
```
------------------------------------------------------------

Class demo scripts:

https://github.com/pingcap/tidb-course-201-lab/blob/master/scripts/07-demo-auto-random-01-show.sql

Note: Please try the following script to see the details.

```
drop table if exists test.ar;

drop table if exists test.dummy;

create table test.ar (id bigint primary key auto_random, name boolean);

insert into test.ar (name) values (null);

insert into test.ar (name) values (null);

select last_insert_id();

select distinct substr(id,1,14) from test.ar; 

select * from information_schema.tables where table_name='ar' and table_schema='test'\G
```

