-2

This is not the whole program I want to write but right now I'm just trying to figure out this simple thing. And if you couldn't tell, I am completely new to programming.

algsim
  • 1
  • Does this answer your question? [Generate random integers between 0 and 9](https://stackoverflow.com/questions/3996904/generate-random-integers-between-0-and-9) – Finncent Price Jan 14 '22 at 16:39
  • This is a duplicate of [How do I create a list of random numbers without duplicates?](https://stackoverflow.com/q/9755538/364696). Would have dupehammered if I hadn't voted to close for lack of focus, oops. – ShadowRanger Jan 14 '22 at 16:48

1 Answers1

1
import random
random.sample(range(10), 10)
  • `random.sample(range(1, 11), 10)` if they must start at 1 and end at 10. – theherk Jan 14 '22 at 16:38
  • and what to write to print – algsim Jan 14 '22 at 16:39
  • @algsim: You need to actually run through a tutorial; printing a `list` item by item is so basic it's not worth covering here. Learn the basics of the language *then* ask questions about more complicated topics, don't learn it by asking a question for literally everything and having an understanding of it with glaring gaps. – ShadowRanger Jan 14 '22 at 16:41
  • 2
    `sample` is the best one-liner, but it is slightly less performant when you need to get all the values anyway; if you need to do this a lot (and are okay with two statements instead of one expression), the faster solution for "randomize order of all values" is `lst = [*range(10)]` (or `lst = list(range(10))` if you don't like unpacking generalizations), followed by `random.shuffle(lst)`. – ShadowRanger Jan 14 '22 at 16:50