# how to generate a random 10 digit integer with 1 at last place?

In sage, how to generate a random 10 digit integer with 1 at last place?

how to generate a random 10 digit integer with 1 at last place?

In sage, how to generate a random 10 digit integer with 1 at last place?

add a comment

0

There is also `randrange`

from the `random`

library which is good for that task:

```
sage: import random
sage: random.randrange(10^9+1, 10^10, 10)
6071633551
```

0

There are many ways.

Here is a simple one using `randint`

:

```
sage: 10 * randint(10^8, 10^9 - 1) + 1
```

0

We can simply generate a random nine-digits integer, then insert a one at the "last" place. Here is a possibility using the random package:

```
sage: import random
sage: a = random.choice(range(10^8, 10^9)) * 10 + 1
sage: a
9768350121
```

Or we offer directly the corresponding range to the `random.choice`

method:

```
sage: random.choice(range(10^9 + 1, 10^10, 10))
8455325531
```

Here, `range(10^9 + 1, 10^10, 10)`

is a range-object, which "consumed" points to the integers taken from $10^9+1$ with step $10$ going up to maximally (and excluding) $10^{10}$. Then `random.choice`

called with this range instance picks one random element of the corresponding list.

Asked: **
2020-05-21 10:39:54 -0500
**

Seen: **65 times**

Last updated: **May 23**

Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.