Skip to main content
replaced http://vi.stackexchange.com/ with https://vi.stackexchange.com/
Source Link

I don't think there's a native function for random numbers in Vimscript.

A way using :python (use it in a function, perhaps, with 10000 and 60 replaced by parameters):

:python <<EOF import vim import random line = vim.current.window.cursor[0] r = getattr(__builtins__, 'xrange', range) # To make it work for both Python 2 & 3 vim.current.buffer[line:line] = list(map(str, random.sample(r(10000), 60))) EOF 

See my answer to Making a box in vim via pythonMaking a box in vim via python for a quick intro on Python scripting in Vim.

Since vim.current.buffer is a list of strings, we can assign a list of strings to it the way we would in Python. random.sample is just the simplest way I can think of to get a list of random integers in Python.

I don't think there's a native function for random numbers in Vimscript.

A way using :python (use it in a function, perhaps, with 10000 and 60 replaced by parameters):

:python <<EOF import vim import random line = vim.current.window.cursor[0] r = getattr(__builtins__, 'xrange', range) # To make it work for both Python 2 & 3 vim.current.buffer[line:line] = list(map(str, random.sample(r(10000), 60))) EOF 

See my answer to Making a box in vim via python for a quick intro on Python scripting in Vim.

Since vim.current.buffer is a list of strings, we can assign a list of strings to it the way we would in Python. random.sample is just the simplest way I can think of to get a list of random integers in Python.

I don't think there's a native function for random numbers in Vimscript.

A way using :python (use it in a function, perhaps, with 10000 and 60 replaced by parameters):

:python <<EOF import vim import random line = vim.current.window.cursor[0] r = getattr(__builtins__, 'xrange', range) # To make it work for both Python 2 & 3 vim.current.buffer[line:line] = list(map(str, random.sample(r(10000), 60))) EOF 

See my answer to Making a box in vim via python for a quick intro on Python scripting in Vim.

Since vim.current.buffer is a list of strings, we can assign a list of strings to it the way we would in Python. random.sample is just the simplest way I can think of to get a list of random integers in Python.

This should make it work for both Python 2 and 3; calling list() on a list() is harmless, so this should be okay as well.
Source Link
Martin Tournoij
  • 64.3k
  • 27
  • 205
  • 280

I don't think there's a native function for random numbers in Vimscript.

A way using :python (use it in a function, perhaps, with 10000 and 60 replaced by parameters):

:python <<EOF import vim import random line = vim.current.window.cursor[0] r = getattr(__builtins__, 'xrange', range) # To make it work for both Python 2 & 3 vim.current.buffer[line:line] = list(map(str, random.sample(xranger(10000), 60))) EOF 

See my answer to Making a box in vim via python for a quick intro on Python scripting in Vim.

Since vim.current.buffer is a list of strings, we can assign a list of strings to it the way we would in Python. random.sample is just the simplest way I can think of to get a list of random integers in Python.

I don't think there's a native function for random numbers in Vimscript.

A way using :python (use it in a function, perhaps, with 10000 and 60 replaced by parameters):

:python <<EOF import vim import random line = vim.current.window.cursor[0] vim.current.buffer[line:line] = map(str, random.sample(xrange(10000), 60)) EOF 

See my answer to Making a box in vim via python for a quick intro on Python scripting in Vim.

Since vim.current.buffer is a list of strings, we can assign a list of strings to it the way we would in Python. random.sample is just the simplest way I can think of to get a list of random integers in Python.

I don't think there's a native function for random numbers in Vimscript.

A way using :python (use it in a function, perhaps, with 10000 and 60 replaced by parameters):

:python <<EOF import vim import random line = vim.current.window.cursor[0] r = getattr(__builtins__, 'xrange', range) # To make it work for both Python 2 & 3 vim.current.buffer[line:line] = list(map(str, random.sample(r(10000), 60))) EOF 

See my answer to Making a box in vim via python for a quick intro on Python scripting in Vim.

Since vim.current.buffer is a list of strings, we can assign a list of strings to it the way we would in Python. random.sample is just the simplest way I can think of to get a list of random integers in Python.

edited body
Source Link
muru
  • 25.4k
  • 8
  • 86
  • 146

I don't think there's a native function for random numbers in Vimscript.

A way using :python (use it in a function, perhaps, with 10000 and 60 replaced by parameters):

:python <<EOF import vim import random line = vim.current.window.cursor[0] vim.current.buffer[line:line] = map(str, random.sample(xrange(10000), 60))) EOF 

See my answer to Making a box in vim via python for a quick intro on Python scripting in Vim.

Since vim.current.buffer is a list of strings, we can assign a list of strings to it the way we would in Python. random.sample is just the simplest way I can think of to get a list of random integers in Python.

I don't think there's a native function for random numbers in Vimscript.

A way using :python (use it in a function, perhaps, with 10000 and 60 replaced by parameters):

:python <<EOF import vim import random line = vim.current.window.cursor[0] vim.current.buffer[line:line] = map(str, random.sample(xrange(10000, 60))) EOF 

See my answer to Making a box in vim via python for a quick intro on Python scripting in Vim.

Since vim.current.buffer is a list of strings, we can assign a list of strings to it the way we would in Python. random.sample is just the simplest way I can think of to get a list of random integers in Python.

I don't think there's a native function for random numbers in Vimscript.

A way using :python (use it in a function, perhaps, with 10000 and 60 replaced by parameters):

:python <<EOF import vim import random line = vim.current.window.cursor[0] vim.current.buffer[line:line] = map(str, random.sample(xrange(10000), 60)) EOF 

See my answer to Making a box in vim via python for a quick intro on Python scripting in Vim.

Since vim.current.buffer is a list of strings, we can assign a list of strings to it the way we would in Python. random.sample is just the simplest way I can think of to get a list of random integers in Python.

Source Link
muru
  • 25.4k
  • 8
  • 86
  • 146
Loading