Git Product home page Git Product logo

Comments (3)

AstraLuma avatar AstraLuma commented on May 24, 2024 1

Xonsh is not a bourne-ish shell. You want @(random.random()).

from xonsh.

anki-code avatar anki-code commented on May 24, 2024

Hello @ksaj!
In xonsh there are many ways to achieve this.

  1. Using alias:
aliases['rnd'] = lambda: __import__('random').randint(0,100) # one liner implementation
echo $(rnd)
# 23
echo $(rnd)
# 43
  1. Using function:
RND = lambda: __import__('random').randint(0,100)
echo @(RND())
# 43
echo @(RND())
# 53

See xonsh-cheetsheet for more ways.

from xonsh.

HLSSLenda avatar HLSSLenda commented on May 24, 2024

@ksaj You can use a @events.on_pre_prompt on your .xonshrc to emulate $RANDOM.

@events.on_pre_prompt
def _():
    import random
    return random.randint(0, 32767)

Now you can use $RANDOM like you would do in bash.

16:48:50 47% jorge@localhost ~ @ $RANDOM
20034
16:48:51 47% jorge@localhost ~ @

from xonsh.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.